1 ms simple java solution


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

Log in to reply
 

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