删除排序链表重复元素

在这里插入图片描述

# 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 None
        re=head
        while head.next:
            if head.val==head.next.val:
                head.next=head.next.next
            else:
                head=head.next
        return re

在这里插入图片描述

发布了115 篇原创文章 · 获赞 0 · 访问量 2108

猜你喜欢

转载自blog.csdn.net/weixin_45569078/article/details/104687535
今日推荐