您的位置:首页 > 其它

FW - check whether tree is balanced or not - find the max and min of one tree- 2013年12月18日13:12:04

2013-12-19 02:12 656 查看
public static int getMaxdepth(Node root)
	{
		if(root!=null)
		{// max the left and right of the tree; the max is the max of left and right tree
			return 1+Math.max(getMaxdepth(root.left_child), getMaxdepth(root.right_child));
		}
		else
		{// if it is null return 0;
			return 0;
		}
	}
	public static int getMindepth(Node root)
	{
		if(root!=null)
		{
			return 1+Math.min(getMindepth(root.left_child), getMindepth(root.right_child));
		}
		else
		{
			return 0;
		}
	}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐