题解 | #判断一个链表是否为回文结构#

判断一个链表是否为回文结构

http://www.nowcoder.com/practice/3fed228444e740c8be66232ce8b87c2f

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

/**
 * 
 * @param head ListNode类 the head
 * @return bool布尔型
 */
function isPail( head ) {
    // write code here
    let arr = [],res = []
    let cur = head
    while(cur){
        arr.push(cur.val)
        res.push(cur.val)
        cur = cur.next
    }
    arr.reverse()
    for(let i = 0;i < arr.length;i++){
        if(arr[i] != res[i]){
            return false
        }
    }
    return true
}
module.exports = {
    isPail : isPail
};

alt

全部评论
这个好理解,真厉害
点赞 回复 分享
发布于 2022-04-01 11:49

相关推荐

Twilight_m...:经典我朋友XXXX起手,这是那种经典的不知道目前行情搁那儿胡编乱造瞎指导的中年人,不用理这种**
点赞 评论 收藏
分享
程序员小白条:找的太晚,别人都是大三实习,然后大四秋招春招的,你大四下了才去实习,晚1年
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务