[leetcode]Maximum Depth of Binary Tree

简单题。顺手就写出来了。

public class Solution {
    public int maxDepth(TreeNode root) {
        // Start typing your Java solution below
        // DO NOT write main() function        
        if (root == null) return 0;
        if (root.left == null && root.right == null) return 1;
        int lmax = maxDepth(root.left) + 1;
        int rmax = maxDepth(root.right) + 1;
        return Math.max(lmax, rmax);       
    }
}

  

posted @ 2013-08-11 02:14  阿牧遥  阅读(195)  评论(0编辑  收藏  举报