0

The below code is for removing duplicates in the sorted linked list but my code doesn't give the right output...if the input is 247 301 443 443 450 523 588 593 839 1035 1301 1403 1493 1494 1574 1650 1720 1815 1853 1868 1917 -1 but my code gives right output for smaller inputs. where is the error in my code??

public class Solution {
public static LinkedListNode<Integer> removeDuplicates(LinkedListNode<Integer> head) {
    LinkedListNode<Integer> t1=head;
    LinkedListNode<Integer> t2=head.next;
    if(head==null || head.next==null)
    {
        return head;
    }

    while(t2!=null)
    {
        if(t1.data==(t2.data) )
        {
            t2=t2.next;
        }
        else
        {
        t1.next=t2;
        t1=t1.next;
        t2=t2.next;
        }
    }
    t1.next=t2;
    return head;

} }

Depanshu
  • 5
  • 2

0 Answers0