leedcode 删除排序列表中的重复元素

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
        if head==None:
            return head
        if head.next==None:
            return head
        cur=head
        while cur.next!=None:
            if cur.val==cur.next.val:
                cur.next=cur.next.next

            else:
                cur=cur.next
        return head

 

posted @ 2024-01-31 22:45  Junior_bond  阅读(6)  评论(0)    收藏  举报