remove duplicates from sorted array 2
code
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int n = nums.size();
if(n <= 2)
{
return n;
}
int prev = 1;
for(int i = 2; i<n; i++)
{
if(nums[i] != nums[prev] || nums[i] != nums[prev-1])
{
nums[++prev] = nums[i];
}
}
return prev+1;
}
};