Easy way in Java


  • -1
    T

    public int removeDuplicates(int[] nums) {
    int len = nums.length;
    int index = 1;
    if(len == 0)return 0;
    int cur = nums[0];
    for(int i = 1; i < len; i++){
    if(nums[i] == cur){
    continue;
    }else{
    nums[index] = nums[i];
    cur = nums[i];
    index++;
    }
    }
    return index;
    }


Log in to reply
 

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