Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def removeDuplicates(self, nums: List[int]) -> int:
- n = len(nums)
- k = 0
- for i in range(n):
- #no need of nums[i] != nums[k-1] only nums[i] != nums[k-2] will suffice and cover this case as array is sorted so if nums[i] is not equal to nums[k-1] then it has to be not equal to nums[k-2] as nums[k-2] <= nums[k-1]
- if (k < 2) or (nums[i] != nums[k-1]) or (nums[i] != nums[k-2]):
- nums[k] = nums[i]
- k += 1
- return k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement