Sobes.tech
Junior — Middle+

Removing duplicates from a sorted singly linked list

livecode

Task condition

Given a sorted singly linked list, remove all duplicate nodes so that each value appears only once. Return the resulting list, preserving the original order of elements.

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

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

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode deleteDuplicates(ListNode head) {

    }
}