一、力扣
1、二分查找
注意,代码找的是数组中第一个大于等于target的下标,可能下标越界
class Solution {
public int search(int[] nums, int target) {
int left=0,right=nums.length;
while(left<right){
int mid=(left+right)/2;
if(nums[mid]<target){
left=mid+1;
}else{
right=mid;
}
}
return left<nums.length&&nums[left]==target?left:-1;
}
}
2、括号生成
class Solution {
List<String> res;
List<String> path;
int n;
public List<String> generateParenthesis(int n) {
res=new ArrayList<>();
path=new ArrayList<>();
this.n=n;
dfs(0,0);
return res;
}
public void dfs(int x,int y){
if(x>n||y>n) return;
if(y>x) return;
if(x==n&&y==n){
StringBuilder temp=new StringBuilder();
for(var e:path){
temp.append(e);
}
res.add(temp.toString());
}
path.add("(");
dfs(x+1,y);
path.removeLast();
path.add(")");
dfs(x,y+1);
path.removeLast();
}
}
3、路径总和
class Solution {
boolean res=false;
public boolean hasPathSum(TreeNode root, int targetSum) {
if(root==null) return false;
dfs(root,targetSum,0);
return res;
}
public void dfs(TreeNode root,int targetSum,int sum){
if(root==null) return;
sum+=root.val;
if(root.left==null&&root.right==null&&sum==targetSum){
res=true;
return;
}
dfs(root.left,targetSum,sum);
dfs(root.right,targetSum,sum);
}
}
4、 从中序与后序遍历序列构造二叉树
class Solution {
int[] inorder,postorder;
public TreeNode buildTree(int[] inorder, int[] postorder) {
this.inorder=inorder;
this.postorder=postorder;
return dfs(0,inorder.length-1,0,postorder.length-1);
}
public TreeNode dfs(int a,int b,int c,int d){
if(a>b||c>d) return null;
int target=postorder[d];
int point=a;
while(inorder[point]!=target){
point++;
}
TreeNode root=new TreeNode(target);
root.left=dfs(a,point-1,c,d+point-b-1);
root.right=dfs(point+1,b,d+point-b,d-1);
return root;
}
}
5、最大二叉树
class Solution {
int[] nums;
public TreeNode constructMaximumBinaryTree(int[] nums) {
this.nums=nums;
return dfs(0,nums.length-1);
}
public TreeNode dfs(int x,int y){
if(x>y) return null;
int max=nums[x];
int point=x;
for(int i=x;i<=y;i++){
if(nums[i]>max){
max=nums[i];
point=i;
}
}
TreeNode root=new TreeNode(max);
root.left=dfs(x,point-1);
root.right=dfs(point+1,y);
return root;
}
}
二、语雀-线上问题排查
1、数据库连接池满排查过程
2、数据库CPU被打满排查过程
3、频繁FullGC问题排查
三、语雀-操作系统
1、进程,线程和协程的区别
2、什么是全双工和半双工
3、进程间通信方式有哪些?
4、什么是用户态、内核态?如何切换的?
5、什么是Load(负载)
6、什么是CPU利用率?怎么算的?
1. CPU利用率与负载
7、什么是时间片
8、你掌握哪些Linux常用命令?
我熟悉Linux常用命令,涵盖文件操作(如ls查看目录、cp/mv/rm复制/移动/删除、cat/less查看文件)、系统管理(如ps/top监控进程、chmod/chown修改权限、df/du查看磁盘空间、apt/yum包管理)、网络工具(如ping/curl测试连接、ssh/scp远程操作、netstat查端口)、文本处理(如grep/sed/awk搜索/编辑、vim/nano编辑器)及压缩归档(tar/gzip)等核心功能,能支持日常运维、脚本编写及故障排查,同时会提醒用户谨慎操作高危命令(如rm -rf)。
9、什么是操作系统的多级缓存
10、什么是MESI缓存一致性协议
1. 缓存一致性协议
11、线程的实现方式有哪些?
1. 使用内核线程实现
2. 使用用户线程实现
12、IO多路复用和多线程有什么区别?
1. IO多路复用
2. 多线程
3. 对比
13、什么是Page Cache,他的读写过程是怎么样的?有什么优缺点?
✅什么是Page Cache,他的读写过程是怎么样的?有什么优缺点?