LeetCode

        递归求二叉树的最大深度。

       

/**
 * Definition for binary tree
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
   public int maxDepth(TreeNode root) {
		 if(root == null)
			 return 0;
		 if(root == null)
			 return 0;
		 int l = maxDepth(root.left);
		 int r = maxDepth(root.right);
		 if(l > r) return l+1;
		 else return r+1;
	 }
	 
}
原文地址:https://www.cnblogs.com/wxisme/p/4457020.html