Java 1ms solution - Simple solution - Two pointers


  • 2
    D
     public int removeDuplicates(int[] nums) {
         if (nums == null || nums.length == 0) return 0;
                int i = 1, j = 0;
                while (i < nums.length) {
                    if (nums[i] > nums[j]) {
                        nums[++j] = nums[i];
                    }
                    i++;
                }
                return j+1;
            }

Log in to reply
 

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