递归是最适合解决树问题的方法。

public class Solution {
//左深度和右深度,返回大的那个
public int TreeDepth(TreeNode root) {
if(root==null) return 0;
return 1+Math.max(TreeDepth(root.left), TreeDepth(root.right));
}

}