Skip to content

Commit

Permalink
Update 26. Remove Duplicates from Sorted Array
Browse files Browse the repository at this point in the history
  • Loading branch information
huihut committed Feb 14, 2018
1 parent 4fd2b0f commit 28dbc29
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Problems/LeetcodeProblems/26-remove-duplicates-from-sorted-array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int n = nums.size(), pos = 0;
if(n <= 1)
return n;
for(int i = 0; i < n-1; ++i) {
if(nums[i] != nums[i+1]) {
nums[++pos] = nums[i+1];
}
}
return pos+1;
}
};

0 comments on commit 28dbc29

Please sign in to comment.