Skip to content

Instantly share code, notes, and snippets.

@EfrainReyes
Created November 11, 2022 01:17
Show Gist options
  • Save EfrainReyes/1bfd3603b0bfcce2a3a589dc33952082 to your computer and use it in GitHub Desktop.
Save EfrainReyes/1bfd3603b0bfcce2a3a589dc33952082 to your computer and use it in GitHub Desktop.
26. Remove Duplicates from Sorted Array (C#)
public class Solution {
public int RemoveDuplicates(int[] nums) {
if (nums.Length == 0)
return 0;
var currentModifiableIndex = 1;
var lastModifiedValue = nums[0];
for (var i = 0; i < nums.Length; i++) {
var currentValue = nums[i];
if (lastModifiedValue < currentValue) {
nums[currentModifiableIndex] = currentValue;
lastModifiedValue = currentValue;
currentModifiableIndex++;
}
}
return currentModifiableIndex;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment