树的最大深度 leecode java

秒杀
/** * 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; } }

  

posted @ 2014-06-30 19:59  hansongjiang8  阅读(428)  评论(0编辑  收藏  举报