题目描述
blablabla
样例
blablabla
算法1
$O(n^2)$
blablabla
时间复杂度分析:blablabla
Python 代码
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def deleteDuplication(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head is None:
return None
dummy = ListNode(1)
dummy.next = head
p = dummy
while p.next:
q = p.next
while q and q.val == p.next.val:
q = q.next
if p.next.next == q:
p = p.next
else:
p.next = q
return dummy.next
感觉这里的py有点少