To solve this problem, you'll have to open it on the computer

Remove Duplicates from Sorted List II

Linked list
medium
Score: 40

Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.

Class Node:
    data (int)
    next (Node)

Input Format:

First Parameter - Node head

Output Format:

Return a Node.

Example 1:

Input:
    1 2 3 3 4 4 5
Output:
    1 2 5

"Remove-duplicates-linked-list-1"

Example 2:

Input:
    1 1 1 2 3 
Output:
    2 3

"Remove-duplicates-linked-list-2"

Constraints:

  • 0<= No. of nodes <= 104
  • -1000 <= Node.data <= 1000
  • Expected Time Complexity: O(n)
  • Expected Auxiliary Space: O(1)
Submit code to see the your result here