2 line Python solution


  • 0
    W
    class Solution(object):
        def removeElement(self, nums, val):        
            nums[:] = filter(lambda x: x != val, nums)
            
            return len(nums)
    

    The nums[:] assignment just replaces the array in place.


Log in to reply
 

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