leetcode ——83. 删除排序链表中的重复元素

实在太开心了!!!!!

独立完成第一道链表题!!!!!!

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        if not head:
            return
        p=head
        q=head.next
        while q:
            if p.val==q.val:
                q=q.next
                p.next=q
            else:
                p=q
                q=q.next
        return head
执行用时 :56 ms, 在所有 python3 提交中击败了76.67%的用户
内存消耗 :14 MB, 在所有 python3 提交中击败了5.01%的用户
 
 
                                                                                ——2019.10.23
posted @ 2019-10-23 20:44  欣姐姐  阅读(97)  评论(0编辑  收藏  举报