-
Notifications
You must be signed in to change notification settings - Fork 0
/
82.py
55 lines (48 loc) · 1.27 KB
/
82.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Definition for singly-linked list.
# add a new head
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Li(object):
def __init__(self, l):
self.head = ListNode(l[0])
cur = self.head
for i in range(1, len(l)):
cur.next = ListNode(l[i])
cur = cur.next
def returnHead(self):
return self.head
def printL(self, head):
cur = head
while cur:
print cur.val,'->',
cur = cur.next
class Solution(object):
def deleteDuplicates(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
h = ListNode(-1)
h.next = head
head = h
cur = head
repeat = False
while cur.next:
while cur.next.next and cur.next.next.val == cur.next.val:
cur.next = cur.next.next
repeat = True
if repeat == True:
cur.next = cur.next.next
repeat = False
else:
cur=cur.next
return head.next
if __name__ == '__main__':
solution = Solution()
li = Li([0,0])
li.printL(li.returnHead())
print
h = solution.deleteDuplicates(li.returnHead())
li.printL(h)