Show my java recursive solutions, only by using stack, no extra space used.


  • 0
    S

    public class Solution {
    boolean isPalin = true;
    public boolean isPalindrome(ListNode head) {
    if(head == null || head.next == null) return true;
    helpder(head,head);
    return isPalin;
    }
    private ListNode helpder(ListNode top,ListNode tail){
    if(tail == null) return top;
    ListNode newTop = helpder(top,tail.next);
    if(newTop.val != tail.val){
    isPalin = false;
    }
    return newTop.next;
    }
    }


Log in to reply
 

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