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

题目描述

image.png

我的解法

# 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:
thead = ListNode('a')
thead.next = head
pre,cur = None,thead
while cur:
pre=cur
cur=cur.next
while cur and cur.next and cur.next.val == cur.val:
t=cur.val
while cur and cur.val==t:
cur=cur.next
pre.next=cur
return thead.next

 

Note:

  • 杭州还是有点小冷。
  • 喝了点小酒 挺晕的。
  • 做链表题想到另外引入头指针。
  • 2020加油!!!!