【leetcode】【104】Maximum Depth of Binary Tree


一、問題の説明
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
二、問題分析
Minimum Depth of Binary Treeとよく似ており,同様の解法である.
三、Java ACコード
public int maxDepth(TreeNode root) {
		return depth(root);
	}
	public int depth(TreeNode node){
		if (node == null) {
			return 0;
		}
		return Math.max(depth(node.left), depth(node.right))+1;
	}