Java 1ms solution


  • 0
    R
    public int removeDuplicates(int[] nums) {
        if(nums==null || nums.length==0){
            return 0;
        }
        int result=0;
        for(int index=1; index< nums.length; index++){
            if(nums[index]==nums[result]){
                continue;
            }
            else{
                nums[++result]=nums[index];
            }
        }
        return result+1;
    }

Log in to reply
 

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