All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : May 22, 2024
Last updated : July 01, 2024
Related Topics : Array, Two Pointers
Acceptance Rate : 58.83 %
class Solution {
public int removeDuplicates(int[] nums) {
int counter = 1;
int shift = 0;
for (int i = 1; i < nums.length; i++) {
if (nums[i] == nums[i - 1]) {
shift++;
} else {
counter++;
}
nums[i - shift] = nums[i];
}
return counter;
}
}