标签:while ext python dup delete else init solution 处理
在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5
利用递归的思想方便理解
# -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteDuplication(self, pHead): # write code here if pHead==None or pHead.next==None: return pHead p=pHead.next if p.val!=pHead.val: pHead.next=self.deleteDuplication(p) else: while p.val==pHead.val and p.next!=None: p=p.next if p.val!=pHead.val: pHead=self.deleteDuplication(p) else: return None return pHead
标签:while ext python dup delete else init solution 处理
原文地址:https://www.cnblogs.com/hit-joseph/p/9462360.html