Python3 solution 109ms


  • 0
    R

    I'm a coding newbie... and am very surprised to see this time OJ said I beat 100% runtime among Python 3 submissions! feels I had to record it :) as I may never get this again :)

    def removeElements(self, head, val):
        while head!=None and head.val==val:
            head=head.next
        if head==None:
            return
        else:
            prev=curr=head
        while curr!=None:
            curr=curr.next
            while curr!=None and curr.val==val:
                curr=curr.next
            prev.next=curr
            prev=curr
        return head
    

Log in to reply
 

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