Skip to content

Instantly share code, notes, and snippets.

@AbhiAgarwal192
Created August 21, 2020 03:43
Show Gist options
  • Save AbhiAgarwal192/78e9ab59d4f4bb099b6b510b2ff81bfb to your computer and use it in GitHub Desktop.
Save AbhiAgarwal192/78e9ab59d4f4bb099b6b510b2ff81bfb to your computer and use it in GitHub Desktop.
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
public class Solution {
public int RemoveDuplicates(int[] nums) {
int len = nums.Length;
if(len == 0 || len == 1){
return len;
}
int j = 0;
int i=1;
while(i<len){
if(nums[i]>nums[j]){
j++;
nums[j] = nums[i];
}
i++;
}
return j+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment