题目链接
83. 删除排序链表中的重复元素 - 力扣(LeetCode)
解题代码
# 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]:current = headwhile current and current.next:if current.val == current.next.val:current.next = current.next.nextelse: current=current.nextreturn head