Skip to content

Commit

Permalink
Create remove-duplicates-sorted.cpp
Browse files Browse the repository at this point in the history
quite a slow solution but it works
  • Loading branch information
gabedonnan authored Mar 29, 2023
1 parent e2d07e9 commit c16142a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions remove-duplicates-sorted.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int numSize = nums.size();
if (numSize == 0) {
return 0;
}
int shift = 0;
int prev = nums[0];
for (int i = 0; i < numSize; i++) {
if (i != 0 && nums[i-shift] == prev) {
nums.erase(nums.begin()+(i-shift));
shift++;
}
prev = nums[i-shift];
}
return nums.size();
}
};

0 comments on commit c16142a

Please sign in to comment.