[Algorithm] Remove Element

class Solution:
    def removeElement(self, nums: List[int], val: int) -> int:
        # while val is in nums, remove it from nums
        # as per the doc:
        #       list.remove(x)
        #           Remove the first item from the list whose value is x. It is an error if there is no such item.
        while val in nums:
            nums.remove(val)

Leave a comment