编程求昨天这个时候的时间,年月日
解释MVC
解释实时数据库实现原理,及分布式原理
列举十个常用的linux命令(top命令详解)
使用过的缓存技术,如redis,文件系统等
阿帕奇服务器的部署步骤
mysql索引优化
求二叉树的最大高度
//求树的最大深度
public static int maxDepth(TreeNode root) {
if(root==null)
return 0;
int leftt=maxDepth(root.left);
int rightt=maxDepth(root.right);
return 1+Math.max(leftt, rightt);
}
扩展:求二叉树最小高度
//求树的最小深度(考虑只有两个节点的情况时最小高度即高度为2)
public static int minDepth(TreeNode root) {
if(root==null)
return 0;
int leftt=minDepth(root.left);
int rightt=minDepth(root.right);
if(leftt==0||rightt==0)//只有两个节点的情况时最小高度即高度为2
return 1+Math.max(leftt, rightt);
return 1+Math.min(leftt, rightt);
}
扩展:求二叉树最大宽度高度(只计算存在的节点个数)
//求树的最大宽度
public static int widthOfBinaryTree(TreeNode root) {
if(root==null)
return 0;
Queue<TreeNode> que=new ArrayDeque<TreeNode>();
que.add(root);//根节点入队
int maxwidth=0;
while(true)//每层一次循环
{
int currentlen=que.size();
if(currentlen<=0)
break;
while(currentlen>0)//每取出一个节点,就把其下一层的孩子节点入队
{
TreeNode t=que.poll();
currentlen--;
if(t.left!=null)
que.add(t.left);
if(t.right!=null)
que.add(t.right);
}
maxwidth=Math.max(maxwidth, que.size());
}
return maxwidth;
}