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