Fast Python Solution that beats 91% submissions


  • 0
    E
    
    class Solution(object):
        def removeElement(self, nums, val):
            count = 0
            index = 0
            for i in range(0,len(nums)):
                if nums[i] == val:
                    count += 1
                else:
                    if index + count < len(nums):
                        nums[index] = nums[index+count]
                    index += 1  
            return len(nums)-count
    
    ```

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.