-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path184.py
More file actions
24 lines (20 loc) · 741 Bytes
/
184.py
File metadata and controls
24 lines (20 loc) · 741 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
from typing import Optional
# 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: Optional[ListNode]) -> Optional[ListNode]:
unique_node = head
cur_node = head
while cur_node is not None:
if cur_node.val != unique_node.val:
unique_node.next = cur_node
unique_node = cur_node
else:
cur_node = cur_node.next
if unique_node is not None and unique_node.next is not None:
if unique_node.val == unique_node.next.val:
unique_node.next = None
return head