O(n) O(1) Recursive Java Solution


  • 0
    public class Solution {
        ListNode curr;
        public boolean isPalindrome(ListNode head) {
            if (head == null || head.next == null) return true;
            curr = head;
            return helper(head);
        }
        private boolean helper(ListNode head) {
            if (head == null) return true;
            if (helper(head.next) && head.val == curr.val) {
                curr = curr.next;
                return true;
            }
            return false;
        }
    }
    

Log in to reply
 

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