Created
November 11, 2022 01:17
-
-
Save EfrainReyes/1bfd3603b0bfcce2a3a589dc33952082 to your computer and use it in GitHub Desktop.
26. Remove Duplicates from Sorted Array (C#)
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) { | |
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