Clean Python Code Beats 86%


  • 0
    W
    class Solution(object):
    def removeElements(self, head, val):
        if head == None:
            return head
        while(head != None and head.val == val):
            head = head.next
        if head == None:
            return head
        prev, current = head, head.next
        while (current != None):
            while (current.val == val):
                prev.next = current.next
                if current.next == None:
                    return head
                current = current.next
            prev,current = current, current.next
        return head

Log in to reply
 

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