树的最大深度 leecode java

时间:2014-07-01 13:16:49   收藏:0   阅读:174
秒杀
/** * 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; int h1=maxDepth(root.left); int h2=maxDepth(root.right); return h1>h2?h1+1:h2+1; } }

  

树的最大深度 leecode java,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!