题解 | #删除有序链表中重复的元素-II#
删除有序链表中重复的元素-II
http://www.nowcoder.com/practice/71cef9f8b5564579bf7ed93fbe0b2024
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
#
#
# @param head ListNode类
# @return ListNode类
#
class Solution:
def deleteDuplicates(self , head ):
# write code here
new_head = ListNode(-1)
new_tail = new_head
temp = head
while temp:
if temp.next and temp.next.val == temp.val:
value = temp.val
while temp and temp.val==value:
temp = temp.next
else:
new_temp = temp.next
new_tail.next = temp
new_tail = new_tail.next
new_tail.next = None
temp = new_temp
return new_head.next