int removeDuplicates(vector<int>& nums) {
int size = nums.size();
int right =1,left = 0;
while (right < size)
{
if ((nums[left] != nums[right]) && (right - left == 1))
{
left++;
right++;
}
else if (nums[left] == nums[right])
{
right++;
}
else
{
nums[++left] = nums[right++];
}
}
return left + 1;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter