自己1:行吧,时间已经击败99%的人了,不想优化了,bingo
# 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:
return None
res = ListNode(-1)
res.next = head
pre = head
tail = head.next
while tail:
if pre.val != tail.val:
pre.next = tail
pre = tail
tail = tail.next
else:
tail = tail.next
pre.next = tail
return res.next