Share my 376ms Java solution


  • 0
    X
    public class Solution {
    public int removeDuplicates(int[] nums) {
        if(nums==null||nums.length==0){
            return 0;
        }
        int i =0,k = 0;
        while(i+k<nums.length){
            while(i+1+k<nums.length&&nums[i]==nums[i+1+k]){
                k++;
            }
            if(i+1<nums.length&&i+k+1<nums.length){
                 nums[i+1]=nums[i+k+1];
            }
            i++;
        }
        return i;
    }
    

    }


Log in to reply
 

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