C# two-pointers Solution


  • 0
    L
    public int RemoveDuplicates(int[] nums) {
        int left = 0, right = 0;
        while(right < nums.Length)
            if(right < nums.Length - 1 && nums[right] == nums[right + 1]){
                nums[left++] = nums[right++]; nums[left++] = nums[right++];
                while(right < nums.Length && nums[right] == nums[right - 1]) right++;
            }
            else nums[left++] = nums[right++];
        return left;
    }

Log in to reply
 

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