Skip to content

Commit 272820a

Browse files
committed
Update solution 082 [Python3]
1 parent 2a57d13 commit 272820a

File tree

1 file changed

+35
-0
lines changed
  • solution/082.Remove Duplicates from Sorted List II

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
class Solution:
8+
def deleteDuplicates(self, head):
9+
"""
10+
:type head: ListNode
11+
:rtype: ListNode
12+
"""
13+
if head == None:
14+
return None
15+
list0=list()
16+
i=head
17+
while i:
18+
list0.append(i.val)
19+
i=i.next
20+
list1=list0.copy()
21+
for i in list0:
22+
c=list0.count(i)
23+
if c != 1:
24+
while 1:
25+
try:
26+
list1.remove(i)
27+
except:
28+
break
29+
30+
new_listnode=ListNode(0)
31+
j=new_listnode
32+
for v in list1:
33+
new_listnode.next=ListNode(v)
34+
new_listnode=new_listnode.next
35+
return j.next

0 commit comments

Comments
 (0)