Problem
Solution
# 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]:
if not head or not head.next:
return head
curr = head
n = head.next
while True:
if curr.val != n.val:
curr.next = n
curr = curr.next
n = n.next
if not n:
curr.next = None
break
return head
Time Complexity
O(N)
Space Complexity
O(1)
'CODE > Algorithms & Data Structures' 카테고리의 다른 글
[Coderust] Remove Nth Node From End of List (0) | 2022.05.18 |
---|---|
[Coderust] Intersection of Two Linked Lists (0) | 2022.05.17 |
[Coderust] Implementation of Linked List (0) | 2022.03.08 |
[Coderust] Merge an Array With Overlapping Intervals (0) | 2022.02.28 |
[Coderust] Stock Buy Sell to Maximize Profit (0) | 2022.02.27 |