[
linked list
]
Leetcode 0083 Remove Duplicates from Sorted List
Problem statement
https://leetcode.com/problems/remove-duplicates-from-sorted-list/
Solution
Go from left to right and check if the current value is equal to the next value.
Complexity
It is O(n)
for time and O(1)
for space, because we modified original list.
Code
class Solution:
def deleteDuplicates(self, head):
curr = head
while curr and curr.next:
if curr.next.val == curr.val:
curr.next = curr.next.next
else:
curr = curr.next
return head