Created
August 21, 2020 03:43
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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