-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy path82.py
More file actions
22 lines (21 loc) · 721 Bytes
/
82.py
File metadata and controls
22 lines (21 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteDuplicates(self, head):
dummy_left, dummy_left.next = ListNode(0), head
prev, prev_num = None, dummy_left
while head:
if prev and prev.val != head.val:
prev_num = prev
if prev and prev.val == head.val:
while head and head.next and head.next.val == head.val:
head = head.next
head = head.next
prev_num.next = head
prev = head
if head:
head = head.next
return dummy_left.next