Leetcode83 删除排序链表中的重复元素

/ 0评 / 0

题目描述

file

解法

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
from collections import defaultdict
class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        cur = head
        if not head:
            return None
        while(cur and cur.next):
            if(cur.val == cur.next.val):
                tmp = cur.next
                cur.next = tmp.next
                del tmp
            else:
                cur = cur.next
        return head

 

Note

发表评论

电子邮件地址不会被公开。