首页 > 代码库 > Lintcode 97.二叉树的最大深度

Lintcode 97.二叉树的最大深度

技术分享

---------------------------------

 

AC代码:

/**
 * 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) {
        if(root==null) return 0;
        return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
    }
}

 

题目来源: http://www.lintcode.com/zh-cn/problem/maximum-depth-of-binary-tree/

 

Lintcode 97.二叉树的最大深度