4-line Python Solution


  • 0
    Y
    def removeElement(self, nums, val):
            """
            :type nums: List[int]
            :type val: int
            :rtype: int
            """
            for i in range(len(nums)-1, -1, -1):
                if nums[i] == val:
                    del nums[i]
            return len(nums)
    

Log in to reply
 

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