/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left = this.right = null; * } * } */ public class Solution { /** * @param root: The root of binary tree. * @return: An integer */ public int maxDepth(TreeNode root) { // write your code here if(root==null) return 0; int left=maxDepth(root.left); int right=maxDepth(root.right); return 1+Math.max(left,right); } }
LintCode 97---二叉树的最大深度
猜你喜欢
转载自www.cnblogs.com/cnmoti/p/10828452.html
今日推荐
周排行