mirror of
https://github.com/20kaushik02/leetcode-gulag.git
synced 2026-01-25 07:34:05 +00:00
let's try this again shall we
problems 1->10 of LC150
This commit is contained in:
14
80-remove-duplicates-from-sorted-array-ii/soln.py
Normal file
14
80-remove-duplicates-from-sorted-array-ii/soln.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def removeDuplicates(self, nums: list[int]) -> int:
|
||||
# two pointer
|
||||
last_unique = 0
|
||||
flag = False
|
||||
for fast in range(1, len(nums)):
|
||||
if nums[last_unique] != nums[fast]:
|
||||
flag = False
|
||||
last_unique += 1
|
||||
nums[last_unique] = nums[fast]
|
||||
elif not flag:
|
||||
flag = True
|
||||
last_unique += 1
|
||||
nums[last_unique] = nums[fast]
|
||||
return last_unique + 1 # zero-indexed
|
||||
Reference in New Issue
Block a user