网易雷火笔试 8.14

1. 最长回文子串
function getLongestPalindrome(str) {
    let res = "";
    for (let i = 0; i < str.length; i++) {
        helper(i, i);
        helper(i, i + 1);
    }
    function helper(l, r) {
        while (l >= 0 && r < str.length && str[l] === str[r]) {
            l--;
            r++;
        }
        const curr_str = str.slice(l + 1, r + 1 - 1);
        if (curr_str.length > res.length) res = curr_str;
    }
    return res;
}
2.已知前序,中序遍历顺序,输出后序遍历顺序
class Node {
    constructor(val) {
        this.val = val;
        this.left = null;
        this.right = null;
    }
}
class Solution {
    constructor() {}
    reConstructBinaryTree(pre, tin) {
        if (pre.length === 0) {
            return null;
        }
        let root = new Node(pre[0]);
        let TinIndex = tin.indexOf(pre[0]);
        root.left = this.reConstructBinaryTree(
            pre.slice(1, TinIndex + 1),
            tin.slice(0, TinIndex)
        );
        root.right = this.reConstructBinaryTree(
            pre.slice(TinIndex + 1),
            tin.slice(TinIndex + 1)
        );
        return root;
    }
    PostTraversal(root) {
        if (root !== null) {
            this.PostTraversal(root.left);
            this.PostTraversal(root.right);
            console.log(root.val);
        }
    }
}
let pre = ["a", "c", "d", "e", "f", "h", "g", "b"];
let tin = ["d", "e", "c", "a", "h", "f", "b", "g"];
let s = new Solution();
let root = s.reConstructBinaryTree(pre, tin);
s.PostTraversal(root);



#网易雷火2023秋招笔试虐我的瞬间#
全部评论
老哥为啥你可以用class,我用class直接报错,只能换function写
点赞 回复 分享
发布于 2022-08-14 17:19
第二题时间直接写实例的答案就对了百分之50
点赞 回复 分享
发布于 2022-08-14 17:10
老哥你这是投的啥岗位,为啥和我题不一样
点赞 回复 分享
发布于 2022-08-14 16:19

相关推荐

牛客965593684号:假的,字节hr都是不会找你内推的,直接就是同学我们约个面试?他们有权限直接捞你的。
点赞 评论 收藏
分享
04-08 13:31
已编辑
门头沟学院 前端工程师
D0cC:京东营收1万多亿人民币,阿里9000多亿,虽然他俩利润都没腾讯和字节多,但是很恐怖了啊,负担了多少打工人的薪水
投递拼多多集团-PDD等公司10个岗位
点赞 评论 收藏
分享
评论
3
12
分享

创作者周榜

更多
牛客网
牛客企业服务