My easy java answer


  • -2
    N
    public boolean isPalindrome(ListNode head) {
        
        List valList = new ArrayList();
        
        //save ListNode's val into an ArrayList
        for(ListNode p=head ; p!=null ; p=p.next)
            valList.add(p.val);
        
        //check Palindrome    
        int len = valList.size();
        for(int i=0 ; i<len/2 ; i++)
            if((int)valList.get(i) != (int)valList.get( (len-1)-i ))
                return false;
                
        return true ;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.