/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
*
* 把单向链表改为双向链表,从头和尾同步遍历,遇到不等return false, 否则最后return true
*/
function isPail( head ) {
// write code here
let current = head;
let tail;
while(current){
if(current.next == null){
tail=current;
}
else{
current.next.prev = current;
}
current = current.next;
}
while(head && tail){
if(head.val != tail.val){
return false;
}
if(head.next===tail||head.next===tail.prev){
break;
}
head = head.next;
tail = tail.prev;
}
return true;
}
module.exports = {
isPail : isPail
};