import java.util.Stack; public class Palindrome { public boolean isPalindrome(ListNode pHead){ ListNode fast = pHead; ListNode slow = pHead; Stack stack = new Stack(); while(fast != null && fast.next != null){ stack.push(slow.val); slow = slow.next; fast = fast.next.next; } if (fast != null) { slow = slow.next; } while(slow != null){ if (stack.pop() != slow.val) { return false; } slow = slow.next; } return true; } }