Easy Java solution


  • 0
    L
    public int removeDuplicates(int[] nums) {
            if(nums==null || nums.length==0) {
                return 0;
            }
            int j=0;
            for(int i=0;i<nums.length;i++) {
                if(nums[j]!=nums[i]){
                    nums[++j]=nums[i];
                }
            }
            return j+1;
        }
    

Log in to reply
 

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