昨天面的乒乓智能就问项目了,所以没写。
一面
项目
如何实现控制的切流
八股
Threadlocal线程池
代码
伪代码
transactionTemplate.execute(
select * from tableA where biz_id = 123 for update;(biz_id 是UK)
B b = select * from tableB where instruction_id = 456 and biz_id =123);
if(b == null){
insert tableB
}
对于mysql 在RR和RC 下,如果tableA biz_id = 123不存在,会重复插入tableB吗,tableB instruction_id = 456 and biz_id 没有UK
leetcode
思路:
- 先从根节点开始,dfs扫一遍全图把父结节保存到HashMap
- 从节点p开始往上找,一路打标记
- 从节点q往上找,找到的第一个带标记的节点就是答案
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
Map<TreeNode, TreeNode> fa = new HashMap<>();
public void dfs(TreeNode root) {
if (root == null) {
return;
}
if (root.left != null) {
fa.put(root.left, root);
dfs(root.left);
}
if (root.right != null) {
fa.put(root.right, root);
dfs(root.right);
}
}
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
dfs(root);
Map<TreeNode, Boolean> vis = new HashMap<>();
while (p != null) {
vis.put(p, true);
p = fa.get(p);
}
while (q != null) {
if (vis.get(q) != null && vis.get(q) == true) {
return q;
}
q = fa.get(q);
}
return root;
}
}