下面的代码用于删除排序链表中的重复项,但我的代码没有给出正确的输出...如果输入是247 301 443 443 450 523 588 593 839 1035 1301 1403 1493 1494 1574 1650 1720 1815 1853 1868 1917 -1但我的代码为较小的输入提供了正确的输出。我的代码中的错误在哪里?
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;
} }