美文网首页
83. Remove Duplicates from Sorte

83. Remove Duplicates from Sorte

作者: 羲牧 | 来源:发表于2020-05-26 13:39 被阅读0次

此题比#82 相对简单一些

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        if head is None:
            return head
        H = ListNode()
        H.next = head
        p = H
        q = H.next
        r = H.next
        while r.next:
            r = r.next
            if r.val == q.val:
                if p == H:
                    H.next = r
                p.next = r
                q = r
            else:
                q = r
                p = p.next
        return H.next
                
                
                
        

相关文章

网友评论

      本文标题:83. Remove Duplicates from Sorte

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