Share my EZ Java solution


  • 0
    L
    public int removeDuplicates(int[] nums) {
        int count = 0;
        int p1 = Integer.MAX_VALUE, p2 = Integer.MAX_VALUE;
        for(int i = 0; i < nums.length; i++) {
            if(p1 == p2 && p2 == nums[i]) {
                // i++;
            } else {
              p1 = p2;
              p2 = nums[i];
              nums[count++] = nums[i];
            }
        }
        return count;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.