26. Remove Duplicates from Sorted Array
√ Accepted
√ 161/161 cases passed (24 ms)
√ Your runtime beats 98.69 % of cpp submissions
√ Your memory usage beats 98.78 % of cpp submissions (10.1 MB)
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if (nums.size() <= 1)
{
return nums.size();
}
int i = 0;
int j = i + 1;
while (j < nums.size())
{
if (nums[j] == nums[i])
{
j++;
}
else
{
i++;
nums[i] = nums[j];
j++;
}
}
return i + 1;
}
};