Skip to content

Instantly share code, notes, and snippets.

@dluciano
Created November 11, 2022 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dluciano/c5d476c1be18a4ac08993962e53c892f to your computer and use it in GitHub Desktop.
Save dluciano/c5d476c1be18a4ac08993962e53c892f to your computer and use it in GitHub Desktop.
26. Remove Duplicates from Sorted Array
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