Update 26. Remove Duplicates from Sorted Array

This commit is contained in:
huihut 2018-02-15 01:27:59 +08:00
parent 4fd2b0fd97
commit 28dbc298bc

View File

@ -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;
}
};