二叉树最大深度的递归实现。
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
import java.lang.*;
public class Solution {
public int maxDepth(TreeNode root) {
int depth1;
int depth2;
if(root == null) return 0;
//左子树的深度
depth1 = maxDepth(root.right);
//右子树的深度
depth2 = maxDepth(root.left);
return Math.max(depth1,depth2)+1;
}
}