2ms Java solution optimized


  • 1
    H
    public int removeDuplicates(int[] nums) {
            int index= 0;
            for(int i =1 ;i <nums.length;i++){
                if(nums[i]!=nums[index]&&i!=++index){
                    nums[index]=nums[i];
                }
            }
            return index+1;
        }

Log in to reply
 

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