Implement a function to remove duplicates from a sorted linked list.
HardProblem Statement
Implement a function to remove duplicates from a sorted linked list.
Sample Input
A sorted linked list: 1 -> 1 -> 2 -> 3 -> 3.
Sample Output
1 -> 2 -> 3 -> null
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
class ListNode(val value: Int) {
var next: ListNode? = null
}
fun removeDuplicates(head: ListNode?): ListNode? {
// Add your code here to remove duplicates
}
fun main() {
// Build linked list and test the function
}
Input
A sorted linked list: 1 -> 1 -> 2 -> 3 -> 3.
Expected Output
1 -> 2 -> 3 -> null