Remove Duplicates from Sorted Array


  • 0
    S

    Can anybody help me with this task? I dont understand I get [1,1], but not [1,2] array???
    ' ' '
    class Solution {
    public int removeDuplicates(int[] nums) {
    int len = nums.length;
    int i = 0;
    while(i + 1 <= len){
    if(nums[i] == nums[i + 1]){
    nums[i] = nums[i + 1];
    len--;
    }

         i++;
      }      
      return len;
    }
    

    }

    ' ' '


Log in to reply
 

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