I am doing a question of eliminating duplicates from LinkedList. have written this code in the if statement first I have written if(curr.data == curr.next.data)
but it is showing wrong and in one test case it is showing runtime error. Isn't Both are same? What is the difference in using (curr.data.equals(curr.next.data))?
public static LinkedListNode<Integer> removeDuplicates(LinkedListNode<Integer> head) {
//Your code goes here
if (head == null)
return null;
LinkedListNode<Integer> curr = head;
while(curr.next != null)
{
if(curr.data == curr.next.data)
{
curr.next = curr.next.next;
}
else
{
curr = curr.next;
}
}
return head;
}