leetcode-83删除排序链表中的重复元素

题目链接

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 = head
        while current and current.next:
            if current.val == current.next.val:
                current.next = current.next.next
            else: current=current.next
        return head

你可能感兴趣的:(leetcode,链表,算法)