Skip to content

Commit

Permalink
Create remove-duplicates.py
Browse files Browse the repository at this point in the history
In place algorithm for duplicate removal
  • Loading branch information
gabedonnan authored Jun 5, 2023
1 parent f216b0c commit c434845
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions remove-duplicates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
p1 = 0
p2 = 0
ln = len(nums)
while p2 < ln:
p1 += 1
curr = nums[p2]
while nums[p2] == curr:
p2 += 1
if p2 == ln:
return p1

nums[p1] = nums[p2]

return p1

0 comments on commit c434845

Please sign in to comment.