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

浙公网安备 33010602011771号