[tag] two pointer.
It's a bit tricky.
- use two pointers one fixed pointer(l) and one floating(r)
- numbers on left of l is in order.
- r will stay unless r found a different value
'''
l
1,1,2,2,2,2,2,2,3,2,3,4
r
'''
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
l, r = 2, 2
while r < len(nums):
if nums[l-2] != nums[r]:
nums[l] = nums[r]
l += 1
r += 1
return l