美文网首页
83. Remove Duplicates from Sorte

83. Remove Duplicates from Sorte

作者: April63 | 来源:发表于2018-06-19 10:39 被阅读0次

用一个指针扫描

# 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
        p = head
        while p:
            if p.next:
                if p.next.val != p.val:
                    p = p.next
                else:
                    q = p.next
                    p.next = q.next
            else:
                break
        return head

相关文章

网友评论

      本文标题:83. Remove Duplicates from Sorte

      本文链接:https://www.haomeiwen.com/subject/fiqaeftx.html