My Simple Java Solution


  • 0
    S
       public int removeDuplicates(int[] nums) {
            int i = 0;
            for(int cur:nums) {
                if(i==0 || (cur != nums[i-1])) {
                    nums[i++] = cur;
                }
            }
            
            return i;
        }

Log in to reply
 

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