-
-
Notifications
You must be signed in to change notification settings - Fork 9k
/
Copy pathSolution.py
35 lines (33 loc) · 880 Bytes
/
Solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteDuplicates(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head == None:
return None
list0=list()
i=head
while i:
list0.append(i.val)
i=i.next
list1=list0.copy()
for i in list0:
c=list0.count(i)
if c != 1:
while 1:
try:
list1.remove(i)
except:
break
new_listnode=ListNode(0)
j=new_listnode
for v in list1:
new_listnode.next=ListNode(v)
new_listnode=new_listnode.next
return j.next