题目描述: alt 解题思路:

用一个数组接收链表中的值,在利用循环分别从数组两侧比较值是否相等,判断是否为回文结构

解题代码:

function isPail( head ) {
    // write code here
    let arr = [];
    let p = head;
    if(head == null) return null;
    while(p) {
        arr.push(p.val);
        p = p.next;
    }
    
    let count = arr.length;
    for(let i = 0; i < (count/2); i++) {
        if(arr[i] !== arr[count - i - 1]) {
           return false;
           }
    }
    return true;
}