Given a singly linked list, determine if it is a palindrome.
Follow up:
Could you do it in O(n) time and O(1) space?
public class Solution {
ListNode h;
public boolean isPalindrome(ListNode head) {
if (head == null) return true;
if (h == null) h = head;
boolean tmp = true;
if (head.next != null) tmp &= isPalindrome(head.next);
tmp &= (head.val == h.val);
h = h.next;
return tmp;
}
}