We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- STL
- Vector-Erase
- Discussions
Vector-Erase
Vector-Erase
Sort by
recency
|
413 Discussions
|
Please Login in order to post a comment
include
include
include
include
include
using namespace std;
int main() { int N; cin>>N;//taking the size of vector vectorv; int i; //giving elements to the vector for (i=0; i>e; v.push_back(e); } int x; cin>>x; //erasing the vector v.erase(v.begin()+(x-1)); int a,b; cin>>a; cin>>b; //position deleting v.erase(v.begin()+(a-1),v.begin()+(b-1)); vector::iterator it; int count=0; for (it=v.begin(); it
// Can anyone help to find out the mistake
include
include
include
include
include
using namespace std;
int main() { vector v; int n,value; cin>>n; for(int i=0;i>value; v.push_back(value); } v.erase(v.begin()+1); v.erase(v.begin()+1,v.begin()+3);
}
all test case clear
how does this code works? for(int i:v){ cout<
Hey!!, So i like tried your solution and it works with every default test case and i compared it to mine but it has a bug, when i submit my code it successfully passes all the test cases except for 1, 2 & 3 which are test cases with very large input and i cant figure out. It'ld be very nice if you could help me with it, here's the code:- #include
include
include
include
include
using namespace std;
int main() {
}
Hi, You need to perform two erase() calls. The first for the index and the second for the range. Try to run your code in paper with different use cases, then you will realize where the issue is.
I actually did figure that out, Here's the final code that i submitted. But Thanks for respondnig! :-
include
include
include
include
include
include
using namespace std;
int main() {
}