Advertisement
smj007

Untitled

Apr 10th, 2025
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. class Solution:
  2.     def removeDuplicates(self, nums: List[int]) -> int:
  3.  
  4.         unique_tracker = 1
  5.         replace_tracker = 1
  6.         count = 1
  7.  
  8.         while unique_tracker < len(nums):
  9.             if nums[unique_tracker] == nums[unique_tracker - 1]:
  10.                 # increase the count
  11.                 count += 1
  12.             else:
  13.                 # stop the count
  14.                 count = 1  # reset count for new number
  15.  
  16.             # only if they are the first 2 number
  17.             # activate the replace trcker - copy and move
  18.             if count <= 2:
  19.                 nums[replace_tracker] = nums[unique_tracker]
  20.                 replace_tracker += 1
  21.  
  22.             # go on as usual
  23.             unique_tracker += 1
  24.  
  25.         return replace_tracker
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement