Please Explain this Solution ! Palindrome Linked List (Recursive Approach)

// Palindrome Linked List
//Input: head = [1,2,2,1]
//Output: true

class Solution {

ListNode node;

public boolean isPalindrome(ListNode head) {

	node=head;
	return checkValue(node);
}
public boolean checkValue(ListNode head)
{

    if(head==null || head.next==null) return true;
	
    boolean isValid=checkValue(head.next);
    node=node.next;

    boolean result= (head.val==node.val)?true:false;
	
    return isValid && result;      
}

}

Comments (0)