Simple Iterative Python Solution

  • 0
        def removeElements(self, head, val):
            :type head: ListNode
            :type val: int
            :rtype: ListNode
            d = ListNode(0)
            curr = d
            while head:
                if head.val != val:
           = head
                    curr =
                head =
            if and == val:
       = None

Log in to reply

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