图片说明

/*
 * function ListNode(x){
 *   this.val = x;
 *   this.next = null;
 * }
 */

/**
 * 
 * @param head ListNode类 the head
 * @return bool布尔型
 */
function isPail( head ) {
    if(!head) return true;
    var stack = [];
    var p = head;
    var s = head;
    while(p){
        stack.push(p);
        p = p.next;
    }
    while(s){
        var n = stack.pop();
        if (s.val !== n.val) {
            return false;
        }
        s = s.next;
    }
    return true;
}
module.exports = {
    isPail : isPail
};