在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5
1 class Solution: 2 def deleteDuplication(self, pHead): 3 if pHead == None or pHead.next == None: 4 return pHead 5 n = pHead.next 6 if pHead.val == n.val: 7 while n and pHead.val == n.val: 8 n = n.next 9 return self.deleteDuplication(n) 10 else: 11 pHead.next = self.deleteDuplication(pHead.next) 12 return pHead 13 # write code here