Leetcode#26 Remove Duplicates from Sorted Array
Published:
Link:
https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/
Solution:
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if (nums.size()<=1)
return nums.size();
int count = 1;
int last = nums[0];
for (int i=1; i<nums.size(); i++) {
if (nums[i] != last) {
nums[count++] = nums[i];
last = nums[i];
}
}
return count;
}
};