Java Recursive Solution


  • 0
    R
    public class Solution {
        public ListNode ln;
        public boolean isPalindrome(ListNode head) {
            if(head==null || head.next==null){
                return true;
            }
            ln=head;
            return isPalin(ln);
        }
        public boolean isPalin(ListNode nod){
            if(nod.next == null){
                return nod.val == ln.val;
            }
            boolean res = isPalin(nod.next);
            ln=ln.next;
            return res && nod.val==ln.val;
        }
    }

Log in to reply
 

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