/*
* 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
};
判断链表是否为回文结构
最新推荐文章于 2022-03-23 16:22:22 发布