mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 23:07:08 +00:00
23 lines
681 B
Python
23 lines
681 B
Python
class Solution:
|
|
def removeDuplicates(self, nums: List[int]) -> int:
|
|
readIndex = 1
|
|
writeIndex = 1
|
|
|
|
lastValueSeen = nums[0]
|
|
numTimesValueSeen = 1
|
|
while readIndex < len(nums):
|
|
if nums[readIndex] == lastValueSeen:
|
|
numTimesValueSeen += 1
|
|
|
|
if numTimesValueSeen <= 2:
|
|
nums[writeIndex] = nums[readIndex]
|
|
writeIndex += 1
|
|
else:
|
|
lastValueSeen = nums[readIndex]
|
|
numTimesValueSeen = 1
|
|
nums[writeIndex] = nums[readIndex]
|
|
writeIndex += 1
|
|
|
|
readIndex += 1
|
|
|
|
return writeIndex |