Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def removeDuplicates(self, nums: List[int]) -> int:
- unique_tracker = 1
- replace_tracker = 1
- count = 1
- while unique_tracker < len(nums):
- if nums[unique_tracker] == nums[unique_tracker - 1]:
- # increase the count
- count += 1
- else:
- # stop the count
- count = 1 # reset count for new number
- # only if they are the first 2 number
- # activate the replace trcker - copy and move
- if count <= 2:
- nums[replace_tracker] = nums[unique_tracker]
- replace_tracker += 1
- # go on as usual
- unique_tracker += 1
- return replace_tracker
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement