好未来PHP视频面试

10 篇文章 0 订阅

编程求昨天这个时候的时间,年月日

解释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;
    }

http://www.cnblogs.com/xudong-bupt/p/4036190.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值