Talentd
FleetCode

83. Remove Duplicates from Sorted List

Easy57.6% acceptance9 companies

Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.

Example 1:

Input: head = [1,1,2]
Output: [1,2]

Example 2:

Input: head = [1,1,2,3,3]
Output: [1,2,3]

Constraints:

  • The number of nodes in the list is in the range [0, 300].
  • -100 <= Node.val <= 100
  • The list is guaranteed to be sorted in ascending order.
10:47
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1# Definition for singly-linked list.
2# class ListNode:
3# def __init__(self, val=0, next=None):
4# self.val = val
5# self.next = next
6class Solution:
7 def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
8
Starter codePython 3Spaces: 4
Examples
Input
[1,1,2]
Input
[1,1,2,3,3]
Your code is saved on this device.Solution