链表_leetcode83

# 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 or not head.next:
return head



pre = head
cur = pre.next
curVal = pre.val

while pre and cur:

while cur and cur.val == curVal:
cur = cur.next

if not cur:
pre.next = None
return head


pre.next = cur
pre = cur
cur = pre.next
curVal = pre.val




return head


原文地址:https://www.cnblogs.com/lux-ace/p/10557174.html