存在一个按升序排列的链表,给你这个链表的头节点 head ,请你删除链表中所有存在数字重复情况的节点,只保留原始链表中 没有重复出现 的数字。
返回同样按升序排列的结果链表。
提示:
[0, 300]
内-100 <= Node.val <= 100
# 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: ListNode) -> ListNode: if head is None or head.next is None: return head dumpy = ListNode() dumpy.next = head prev, mid, cur = dumpy, head, head.next while cur: flag = False while cur and mid.val == cur.val: flag = True cur = cur.next if flag: prev.next = cur mid = cur if cur: cur = cur.next else: prev, mid, cur = prev.next, mid.next, cur.next return dumpy.next 作者:mnxiao 链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/solution/python3-shi-xian-shan-chu-pai-xu-lian-bi-41zy/ 来源:力扣(LeetCode) 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。