Last active
November 11, 2022 01:17
-
-
Save EfrainReyes/e13b9873a86fd03912f9c4c14c55a4f6 to your computer and use it in GitHub Desktop.
26. Remove Duplicates from Sorted Array (Python)
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
class Solution: | |
def removeDuplicates(self, nums: List[int]) -> int: | |
if len(nums) == 1: | |
return 1 | |
non_dupes_ptr = 1 | |
for num in nums: | |
if nums[non_dupes_ptr - 1] < num: | |
nums[non_dupes_ptr] = num | |
non_dupes_ptr += 1 | |
return non_dupes_ptr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment