• # leetcode——82. 删除排序链表中的重复元素 II

简直痛哭流涕！！！！！

又一次做出来了链表题，而且是中等难度！！！而且效果不错！！！！

```# 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:
return
return
q=p.next
while p:
if r.val==p.val:
#print(r.val)
a=r.val
r=q
#print(a)
while r.val==a and r.next!=None:
r=r.next
if r.val==a:
return
#print(r.val)
if r.next!=None:
p=r.next
else:
#print(p.val)
if p.next!=None:
q=p.next
else:
if r.val==p.val:
return
elif p.next!=None and p.val==q.val:
b=p.val
if q.next==None:
r.next=None
p=q.next
while p.val==b and p.next!=None:
p=p.next
#print(r.val,p.val,b)
if p.val==b:
r.next=None
q=p.next
r.next=p
#print(r.val,p.val,q.val)
else:
if r.next==None:
else:
r=r.next
if p.next==None:
else:
p=p.next
if q.next==None:
else:
q=q.next
执行用时 :48 ms, 在所有 python3 提交中击败了94.44%的用户
内存消耗 :13.9 MB, 在所有 python3 提交中击败了5.26%的用户

但是看看人家的例子，好简洁：
```执行用时为 36 ms 的范例
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
dummy = ListNode(0)
while fast:
while fast.next and fast.next.val == fast.val:
fast = fast.next
if slow.next == fast:
slow = fast
else:
slow.next = fast.next
fast = fast.next
return dummy.next```

——2019.10.23

我的前方是万里征途，星辰大海！！
• 相关阅读:
【整理】close 和 shutdown 的原理
【理解】 Error 10053和 Error 10054