My solution in Python


  • 0
    B

    Hi everyone,

    Here it is my solution in python. Any comments are welcome.

    Best

    class Solution(object):
        def removeElement(self, nums, val):
            """
            :type nums: List[int]
            :type val: int
            :rtype: int
            """
            
            lnum=len(nums)       
            flag=0
            for i in range(lnum):
                if flag>0:
                    if nums[i-flag]==val:
                        nums.remove(nums[i-flag])
                        flag+=1
                
                if flag==0:                
                    if nums[i]==val:
                        nums.remove(nums[i])
                        flag+=1
    

Log in to reply
 

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