Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
499 B
2
Indexable
Never
class Solution {
    public int removeDuplicates(int[] nums) {
        int curr = 0;
        boolean twice = false;
        int currIndex = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[curr]) {
                nums[currIndex++] = nums[i];
                curr = i;
                twice = false;
            } else if (!twice) {
                twice = true;
                nums[currIndex++] = nums[i];
            }
        }
        return currIndex;
    }
}