Java clean code


  • 0
    J
        public int removeDuplicates(int[] nums) {
            if (nums.length <= 1) return nums.length;
            int i = 1, j = 0;
            while (i < nums.length) {
                if (nums[i] != nums[j]) {
                    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.