remove_duplicates_from_sorted_list

  • 2022-12-14
  • 浏览 (550)

remove_duplicates_from_sorted_list.py 源码

# 删除排序链表中的重复元素

class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:

    def deleteDuplicates(self, head: ListNode) -> ListNode:
        p = head
        while p and p.next:
            if p.val == p.next.val:
                p.next = p.next.next
            else:
                p = p.next
        return head

你可能感兴趣的文章

add_two_numbers

delete_nth_node

intersection_of_two_linked_lists

0  赞