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
What's wrong with my code...tried several times

# Definition for singlylinked 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