标签:注意 ret elf link 简单 leetcode cto nod bsp
这道题虽然简单,但是需要注意的点还是比较多,首先是如果一直有重复的duplicate,要把所有的都去掉,所以inner loop是while而不是if,其次是每一层loop结束的条件,要搞清楚是head,还是head.next是不是None。
最后学习一下在python中如何建立一个class并且写出constructor
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteDuplicates(self, head: ListNode) -> ListNode: if head is None: return head dummy = ListNode(0) dummy.next = head while head is not None: while head.next is not None and head.val == head.next.val: head.next = head.next.next head = head.next return dummy.next
[LeetCode] 83. Remove Duplicates from Sorted List
标签:注意 ret elf link 简单 leetcode cto nod bsp
原文地址:https://www.cnblogs.com/codingEskimo/p/12233690.html