搞半天襟企,總報錯嘱么,細節(jié)問題
class Solution:
def deleteDuplication(self, pHead):
if pHead == None:
return pHead
dummy = ListNode(0)
dummy.next = pHead
pre = dummy
p = pHead
while p and p.next:
if p.next.val == p.val:
val = p.val
while p and p.val == val:
p = p.next
pre.next = p
else:
pre = p
p = p.next
return dummy.next
這一版是留下重復的結點,比較簡單
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteDuplication(self, pHead):
if pHead == None:
return pHead
dummy = ListNode(0)
dummy.next = pHead
pre = dummy
p = pHead
while p:
while p.next and p.next.val == p.val:
p = p.next
pre.next = p
pre = p
p = p.next
return dummy.next