每日一题 83. 删除排序链表中的重复元素(简单)

在这里插入图片描述

# 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]:
        if head == None:
            return head
        t = head
        while t.next != None:
            if t.val == t.next.val:
                t.next = t.next.next
            else:
                t = t.next

        return head

你可能感兴趣的:(用Python刷力扣,链表,数据结构,python,leetcode)