1
var deleteDuplicates = function (head) {
2
// Special case...
3
if (head == null || head.next == null) return head;
4
// Initialize a pointer curr with the address of head node...
5
let curr = head;
6
// Traverse all element through a while loop if curr node and the next node of curr node are present...
7
while (curr != null && curr.next != null) {
8
// If the value of curr is equal to the value of prev...
9
// It means the value is present in the linked list...
10
if (curr.val == curr.next.val) {
11
// Hence we do not need to include curr again in the linked list...
12
// So we increment the value of curr...
13
curr.next = curr.next.next;
14
}
15
// Otherwise, we increment the curr pointer...
16
else {
17
curr = curr.next;
18
}
19
}
20
return head; // Return the sorted linked list without any duplicate element...
21
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0