Share my python solution


  • 0
    F
    class Solution(object):
        def removeElement(self, nums, val):
            """
            :type nums: List[int]
            :type val: int
            :rtype: int
            """
            
           
            i=0
            while i<len(nums):
                if nums[i]==val:
                    tmp=nums.pop()
                    if i<len(nums):
                        nums[i]=tmp
                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.