# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def deleteDuplicates(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if not head or not head.next: return head
dummy=ListNode(0)
dummy.next=head
pre=dummy
start=head
curr=head.next
while curr:
if curr.val==start.val:
while curr and curr.val==start.val:
curr=curr.next
pre.next=curr
start=curr
curr=curr.next if curr else None
else:
pre,start,curr=pre.next,start.next,curr.next
return dummy.next
82. Remove Duplicates from Sorted List II
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- Given a sorted linked list, delete all nodes that have du...
- Given a sorted linked list, delete all nodes that have du...
- 考慮到頭兩個(gè)可能就是重復(fù),申請(qǐng)使用一個(gè)dummy節(jié)點(diǎn),1 ,當(dāng)遇見前后重復(fù)的節(jié)點(diǎn)就刪除當(dāng)前節(jié)點(diǎn),并記錄下重復(fù)節(jié)點(diǎn)的...
- Given a sorted linked list, delete all nodes that have du...
- 題目82. Remove Duplicates from Sorted List II Given a sorte...