mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
Update 26. Remove Duplicates from Sorted Array
This commit is contained in:
parent
4fd2b0fd97
commit
28dbc298bc
|
@ -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;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user