Skip to content

Commit

Permalink
Re-solve "Remove Duplicates from Sorted Array"
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Jan 31, 2024
1 parent f2e2479 commit 1fa223b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/remove_duplicates_from_sorted_array.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
class Solution:
def removeDuplicates(self, nums: list[int]) -> int:
if not nums:
return 0

to_insert = 1
j = 1

for i in range(1, len(nums)):
if nums[i] != nums[to_insert - 1]:
nums[to_insert] = nums[i]
to_insert += 1
if nums[i - 1] == nums[i]:
continue
nums[j] = nums[i]
j += 1

return to_insert
return j

0 comments on commit 1fa223b

Please sign in to comment.