Skip to content

Commit

Permalink
Create 0026-Remove-Duplicates-from-Sorted-Array.cpp
Browse files Browse the repository at this point in the history
C++
  • Loading branch information
kabirdhillon7 committed Dec 29, 2022
1 parent 324cd74 commit e8d1b4f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cpp/0026-Remove-Duplicates-from-Sorted-Array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int left = 1;

for(int right = 1; right < nums.size(); right++){
if(nums[right] != nums[right - 1]){
nums[left] = nums[right];
left++;
}
}

return left;
}
};

0 comments on commit e8d1b4f

Please sign in to comment.