1
var deleteDuplicates = function (head) {3
if (head == null || head.next == null) return head;4
// Initialize a pointer curr with the address of head node...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;15
// Otherwise, we increment the curr pointer...20
return head; // Return the sorted linked list without any duplicate element...