6 lines java. No reverse, No modify list. only recursion;


  • -2
    M
    public class Solution {
        ListNode head = null;
        public boolean isPalindrome(ListNode h) {
            if(this.head == null) this.head = h;
            if (h == null) return true;
            if (!rec(h.next)) return false;
            if (h.val != head.val) return false;
            head = head.next;
            return true;
        }
    

  • 0
    F

    The code seems incomplete... Are you sure it can be resolved with only 6 lines?


Log in to reply
 

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