Simple 12ms C solution


  • 0
    Z
    int removeDuplicates(int* nums, int numsSize) {
      if(nums == NULL || numsSize == 0)
        return 0;
    
      int i;
      int k = 1;
    
      for(i = 1; i<numsSize; i++)
      {
        if(nums[i] > nums[k-1])
        {
          //swap
          if(i>k)
          {
            nums[i] = nums[i] + nums[k];
            nums[k] = nums[i] - nums[k];
            nums[i] = nums[i] - nums[k];
          }
          k++;
        }
      }
    
      return k;
    }

Log in to reply
 

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