My Python in place solution for your reference


  • 0
    K
    class Solution(object):
    def removeElement(self, nums, val):
        i, k, length = 0, 0, len(nums)
        while i<length-k:
            if nums[i] == val:
                k+=1
                del nums[i]
            else:
                i+=1
        return len(nums)

Log in to reply
 

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