Remove duplicates from a sorted list
Easylinked list
The list is sorted in ascending order. Remove duplicate nodes so each value appears once, and return the list.
Example 1
Input: head = [1,1,2] Output: [1,2]
Example 2
Input: head = [1,1,2,3,3] Output: [1,2,3]
Constraints
- 0 ≤ number of nodes ≤ 300
- -100 ≤ Node.val ≤ 100
- The list is sorted
Submit checks your solution against 8 tests, including hidden ones.
// Provided by the judge: keep these definitions
class ListNode {
constructor(val = 0, next = null) {
this.val = val
this.next = next
}
}
/**
* @param {ListNode|null} head
* @return {ListNode|null}
*/
function deleteDuplicates(head) {
}