fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int removeElement(vector<int>& nums, int val) {
  5. int n = nums.size();
  6. int j = 0;
  7. for(int i = 0; i < n; i++){
  8. if(nums[i] != val){
  9. nums[j++] = nums[i];
  10. }
  11. }
  12. return j;
  13. }
  14.  
  15. int main() {
  16. vector<int> nums(4);
  17. nums[0] = 3;
  18. nums[1] = 2;
  19. nums[2] = 3;
  20. nums[3] = 2;
  21. int x = removeElement(nums, 3);
  22. for(int i = 0 ; i < x; i++){
  23. cout << nums[i] << " " ;
  24. }
  25. cout << endl;
  26. return 0;
  27. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
2 2