2ms Java solution with 3 lines of code.


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

  • 0
    A

    some people just love down voting without giving a reason...


Log in to reply
 

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