83. 删除排序链表中的重复元素 - 力扣(LeetCode)


python代码:
# Definition for singly-linked list.
# 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]:
cur = head
while cur and cur.next:
if cur.val == cur.next.val:
cur.next = cur.next.next # Skip the duplicate
else:
cur = cur.next # Move to the next node
return head
481

被折叠的 条评论
为什么被折叠?



