首页 > momenta一面
头像
peonyX
编辑于 2021-07-13 23:18
+ 关注

momenta一面

momenta一面

22届双非本科夹缝中生存,自己的语言是Java,面试官用go,所以没聊太多Java相关的

整个过程19分钟,最后算法做了半个多小时。

  1. 单例模式的实现方式?他跟我说有七种。我只知道双重锁,懒汉饿汉,这三种。我直接懵了,第一个就不会。
  2. Java的垃圾回收。强项,他不打断我我能说十分钟。
  3. 标记清除的优点和缺点,标记整理的优点和缺点。深入理解jvm有写。
  4. b树和b+树区别,时间复杂度是多少。开始我没分析出来,我把b+树和b树的种种区别列出来,然后引导我分析的。b树是logmn,m是底数是分的叉数,n是指数是层数。
  5. 用过MySQL的窗口函数吗?没用过,那要是查询一个表中每个班级的前五名怎么写。我说了两种,嵌套查询和left join。leetcode有类似的:https://leetcode-cn.com/problems/department-top-three-salaries/
  6. 算法:
    树上的每个节点都有一个权值,权值均>=0。现在需要从根节点出发,找到一条路径(不需要非得到叶子节点),使路径上的权值和为n。将路径打印出来,用尽量少的内存和时间,写出核心代码即可,结果直接print打印,不要用数组存储,正序反序均可,打印格式随意。
    // 例如,树的结构为

// 0 1,2,3

// 1 4

// 2 6

// 4 5 7

// 第一个数字代表父节点的序号,第二个数字列表代表当前父节点连接了哪些子节点。

// 节点权值为{5,7,3,8,2,1,1,6}

// 如果n = 20,则其中一条路径为 0,1,4,7 hit: 5 + 7 + 2 + 6 = 20

原来用list存储了一下,面试官问我能不能不用list存储,这里想了好久。

import java.util.*;

public class Main {
    public static void main(String[] args) {
        //System.out.println("Hello World!");
        TreeNode a = new TreeNode(0, 5);
        TreeNode b = new TreeNode(1, 7);
        TreeNode c = new TreeNode(2, 3);
        TreeNode d = new TreeNode(3, 8);
        TreeNode e = new TreeNode(4, 2);
        TreeNode f = new TreeNode(5, 1);
        TreeNode g = new TreeNode(6, 1);
        TreeNode h = new TreeNode(7, 6);
        a.children.add(b);
        a.children.add(c);
        a.children.add(d);
        b.children.add(e);
        e.children.add(g);
        e.children.add(h);
        c.children.add(f);
        int n = 20;
        ShowMeBug solution = new ShowMeBug();
        List<Integer> list = new ArrayList();
        list.add(a.val);
        //System.out.println(a.val);
        solution.dfs(a, a.val, list, n);
        //System.out.println(res);
    }
    static List<Integer> res = null;
    public int dfs(TreeNode root, int path, List<Integer> list, int target) {
        //System.out.println(root.id+" "+path);
        if (res != null) {
            return 0;
        }
        if (target == path) {
            //res = new ArrayList();
            //for (Integer i : list) {
            //  res.add(i);
            //}
            System.out.println(root.val);
            return 1;
        }
        if (root == null) {
            return 0;
        }
        //path += root.val;
        List<TreeNode> children = root.children;
        for (TreeNode child : children) {
            //list.add(child.val);
            int r = dfs(child, path + child.val, list, target);
            //list.remove(list.size() - 1);
            if (r == 1) {
                System.out.println(root.val);
                return 1;
            }
        }
        return 0;

    }


}
class TreeNode {
    public Integer id;
    public Integer val;
    public List<TreeNode> children;
    public TreeNode(Integer id, Integer val) {
        this.id = id;
        this.val = val;
        this.children = new ArrayList();
    }
}

兄弟们不要问过不过了,过了自然更新。反正我是一块砖,哪里需要哪里搬,哪过了去哪。

更多模拟面试

全部评论

(4) 回帖
加载中...
话题 回帖