为了检查链表是否是回文,如果有人能在下面的代码中说出什么地方不对,我将非常感谢

问题描述

代码工作正常,但是当比较两个具有两位以上的负整数时,其返回false。如果有人能告诉我下面的代码有什么问题,我将不胜感激。
例如[.-200,-200]这是一个回文,但与之相比,返回假

class Solution {
public boolean ispalindrome(ListNode head) {
    ArrayList<Integer>list=new ArrayList<>();
    ListNode temp=head;
    while(temp!=null){
        list.add(temp.val);
        temp=temp.next;
    }
    int i=0,j=list.size()-1;
    while(i<j){
        if(list.get(i)!=list.get(j)) return false;
        i++;j--;
    }
    return true;
}

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)