package linkedList;

/**
 * Created by cuixiaodao on 12/15/2017
 * for leetCode problem:
 * https://leetcode.com/problems/palindrome-linked-list/description/
 */

public class PalindromeLinkedList {
    public boolean isPalindrome(ListNode head) {
        int len = 0;
        ListNode walk = head;
        while (walk != null) {
            len++;
            walk = walk.next;
        }

        walk = head;
        int i = 0, mid = len / 2;
        while (i++ < mid) walk = walk.next;
        ListNode end = reverseList(walk);

        walk = head;
        i = 0;
        while (i++ < mid)
            if (walk.val == end.val) {
                walk = walk.next;
                end = end.next;
            } else return false;

        return true;
    }

    private ListNode reverseList(ListNode head) {
        ListNode reverseHead = null;
        while (head != null) {
            ListNode curNode = head;
            head = head.next;

            curNode.next = reverseHead;
            reverseHead = curNode;
        }

        return reverseHead;
    }
}
@@ -233,32 +233,64 @@
 istNode head) %7B%0A
+        // %E6%8E%A8%E5%AF%BC%EF%BC%8C%E7%BB%86%E5%8C%96%E6%98%8E%E7%A1%AE%E9%97%AE%E9%A2%98 -%3E %E7%BF%BB%E8%BD%AC%E5%90%8E%E5%8D%8A%E6%AE%B5%E9%93%BE%E8%A1%A8%0A
         int len 
@@ -1093,8 +1093,9 @@
 %0A    %7D%0A%7D
+%0A

Update PalindromeLinkedList.java