和c有点不一样,Python不需要释放被删除的节点
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteDuplicates(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head is None:
return None
pre,hthis = head,head.next
while hthis:
if pre.val == hthis.val
pre.next = hthis.next
hthis = hthis.next
else:
pre = pre.next
hthis = hthis.next
return head