Skip to content

Commit cab490f

Browse files
authored
Merge pull request #1670 from kabirdhillon7/26
Create 0026-Remove-Duplicates-from-Sorted-Array.cpp
2 parents d6da406 + e8d1b4f commit cab490f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int removeDuplicates(vector<int>& nums) {
4+
int left = 1;
5+
6+
for(int right = 1; right < nums.size(); right++){
7+
if(nums[right] != nums[right - 1]){
8+
nums[left] = nums[right];
9+
left++;
10+
}
11+
}
12+
13+
return left;
14+
}
15+
};

0 commit comments

Comments
 (0)