题目描述
在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 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