Advertisement
smj007

Untitled

Mar 9th, 2025
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. class Solution:
  2.     def removeElement(self, nums: List[int], val: int) -> int:
  3.        
  4.         val_till_now = 0
  5.        
  6.         for index, num in enumerate(nums):
  7.             if num == val:
  8.                 val_till_now += 1
  9.             else:
  10.                 nums[index-val_till_now] = nums[index]
  11.                
  12.         return len(nums) - val_till_now
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement