My python code for your reference, 36ms


  • 0
    class Solution(object):
        def removeElement(self, nums, val):
            """
            :type nums: List[int]
            :type val: int
            :rtype: int
            """
            prev = 0
            for curr in range(len(nums)):
                if nums[curr] == val:
                    continue
                nums[prev] = nums[curr]
                prev += 1
            return prev

Log in to reply
 

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