Created
November 11, 2022 10:17
-
-
Save dluciano/c5d476c1be18a4ac08993962e53c892f to your computer and use it in GitHub Desktop.
26. Remove Duplicates from Sorted Array
This file contains 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) { | |
var i = 1; | |
var j = 1; | |
var k = 1; | |
var last = nums[0]; | |
while(i < nums.Length){ | |
while(i < nums.Length && nums[i] <= last) | |
i++; | |
if(i == nums.Length) | |
continue; | |
last = nums[i]; | |
nums[j] = last; | |
i++; | |
j++; | |
k++; | |
} | |
return k; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment