Share Python easy answer


  • 1
    W
    class Solution(object):
        def removeElement(self, nums, val):
            """
            :type nums: List[int]
            :type val: int
            :rtype: int
            """
            n,count,i=len(nums),0,0
            while i<n-count:
                if nums[i]==val:
                    count+=1
                    nums.pop(i)
                else:
                    i+=1

  • 0
    M
    class Solution(object):
        def removeElement(self, nums, val):
            """
            :type nums: List[int]
            :type val: int
            :rtype: int
            """
            while(val in nums):
                nums.remove(val)
            return len(nums)

Log in to reply
 

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