链表_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


posted @ 2019-03-19 10:53  AceKo  阅读(92)  评论(0编辑  收藏  举报