Simple Python Solution


  • 4
    Y
    def removeElements(self, head, val):
            
            dummy = ListNode(-1)
            dummy.next = head
            pointer = dummy
            
            while(pointer.next):
                
                if pointer.next.val == val:
                    pointer.next = pointer.next.next
                else:
                    pointer = pointer.next
                    
            return dummy.next

  • 0
    G

    Identical as mine. Use dummy node to get rid of the trouble of head.


Log in to reply
 

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