问题
解答
时间复杂度 :O(n)
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
p = head
if p==None or p.next == None:
return head
while p.next:
if p.val == p.next.val:
p.next = p.next.next
else:
p = p.next
return head