0

This code is working fine but when two negative Integers having more than two digits are compared its returning false. I would really appreciate if anyone could tell me what is wrong in the following code.
eg.. [-200,-200] this is a palindrome but when compared its returning false

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;
}

}

0 Answers0