56. Delete duplicate node list (python)

Title Description

In a sorted linked list nodes duplicate, delete the duplicate node list, the node does not retain repeated, returns the head pointer list. For example, the list 1-> 2-> 3-> 3-> 4-> 4-> 5 is treated 1-> 2-> 5
 1 class Solution:
 2     def deleteDuplication(self, pHead):
 3         # write code here
 4         Head = ListNode(-1)
 5         Head.next = pHead
 6         pre = Head
 7         last = Head.next
 8         while last:
 9             if last.next and last.val == last.next.val:
10                 while last.next and last.val == last.next.val:
11                     last = last.next
12                 pre.next = last.next
13                 last = last.next
14             else:
15                 pre = pre.next
16                 last = pre.next
17         return Head.next

2020-01-01 16:22:31

Guess you like

Origin www.cnblogs.com/NPC-assange/p/12129152.html