What's wrong with my code...tried several times


  • 0
    E
        L = list()
        if head == None:
            return head
            
        node = head
        while node.next != None:
            if node.val in L:
                node.next = node.next.next
            else:
                L.append(node.val)
                node = node.next
        
        return head

  • 0
    S
    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        # @param head, a ListNode
        # @return a ListNode
        def deleteDuplicates(self, head):
            L = list()
            if head == None:
                return head
        
            node = head
            L.append(head.val)
            while node.next != None:
                if node.next.val in L:
                    node.next = node.next.next
                else:
                    L.append(node.next.val)
                    node = node.next
        
            return head

Log in to reply
 

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