6-line Python solution, 48 ms


  • 3
    K
    def removeElement(self, nums, val):
        i = 0
        for x in nums:
            if x != val:
                nums[i] = x
                i += 1
        return i

Log in to reply
 

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