-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteDuplicates.py
More file actions
32 lines (30 loc) · 951 Bytes
/
Copy pathdeleteDuplicates.py
File metadata and controls
32 lines (30 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/user/bin/env python
# coding=utf-8
"""
@project : algorithmPython
@ide : PyCharm
@file : deleteDuplicates
@author : illusion
@desc : 82. 删除排序链表中的重复元素 II https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/
@create : 2020-08-30 16:11:21
"""
# 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 not head:
return None
new_head = ListNode(-1)
new_head.next = head
now = new_head
while now.next and now.next.next:
if now.next.val == now.next.next.val:
repeat_val = now.next.val
while now.next and now.next.val == repeat_val:
now.next = now.next.next
else:
now = now.next
return new_head.next