My Java 2ms solution


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

Log in to reply
 

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