作者:yakouhao
链接:https://www.nowcoder.com/discuss/417666?type=post&order=time&pos=&page=1&channel=
来源:牛客网
写在前面:
看了很多牛客的面经,扫一眼问题内容,觉得里面的xx问题,自己复习的时候有cover到,真正面试时候,才知道自己有多naive。
注重原理 不等于 背会原理,也 不等于 只看原理不看应用。没有真材实料,真的是不堪一击。
一面问题:
算法题:
1. 找一棵树距离根结点最深的叶子结点集合
深度优先搜索
(1)维护全局变量maxDep,也就是最大深度,默认为-1
(2)节点深度小于等于max,继续搜索(假设树根节点位于第0层)
(3)节点深度dep大于max,把max设置为当前的深度dep。
之后递归对左右子树调用函数,不过dep要加一(看下面代码就知道了)
运行完,maxDep就知道了
这个代码是1302的代码,求层数最深的叶子结点的和
class Solution { int maxDepth = -1; int sum = 0; public int deepestLeavesSum(TreeNode root) { return dfs(root, 0); } private int dfs(TreeNode root, int depth) { if (root == null) { return 0; } if (maxDepth < depth) { maxDepth = depth; sum = root.val; } else if (depth == maxDepth) { sum += root.val; } if (root.left != null) { dfs(root.left, depth + 1); } if (root.right != null) { dfs(root.right, depth + 1); } return sum; } }
之后层次遍历,找到对应的层数,把队列里面的元素加入集合。
2. 数据处理,30亿行的文件,写的是用户id,找不重复的用户id有多少,允许精确度丢失1%
不会
问答题:
(1)String类型list转long类型,考察Arraylist和LinkedList
Long.parseLong()

(2)hashmap put get 方法。map.put(1L, "1"); map.get(1)输出的是什么(我感觉输出是null,因为get是对key来说的)

(3)mysql,innodb索引如何实现范围查找(半懂)

(4)二级索引叶子结点存放的是什么(二级索引,也就是上面innoDB引擎的辅助索引,存储的是主键值)
(5)覆盖索引是什么,在编写sql的时候要注意哪些问题

(6)数据库隔离原则,以及常用隔离原则的实现原理(原理不清楚)

(7)操作系统虚拟内存置换算法
不懂
(8)TCP三次握手,四次挥手,以及原因https://github.com/CyC2018/CS-Notes/blob/master/notes/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%20-%20%E4%BC%A0%E8%BE%93%E5%B1%82.md#tcp-%E7%9A%84%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B
(8)TCP三次握手,四次挥手,以及原因https://github.com/CyC2018/CS-Notes/blob/master/notes/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%20-%20%E4%BC%A0%E8%BE%93%E5%B1%82.md#tcp-%E7%9A%84%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B


(9)SYN Flood 半开放攻击
不懂
(10)java内存模型
(10)java内存模型


(11)volatile关键字,讲一下原理和应用的场景
加了volatile关键字的代码生成的汇编代码发现,会多出一个lock前缀指令。Lock指令对Intel平台的CPU,早期是锁总线,这样代价太高了,后面提出了缓存一致性协议,MESI,来保证了多核之间数据不一致性问题。保证线程读到的永远是最新值。
volatile关键字是用来保证有序性和可见性的。
(12)bash
不懂
这其中有一部分问题因为我的无知所以面试官也跳过了,总之一场下来,让自己清晰地认识到自身的局限,凉凉。