104. Maximum Depth of Binary Tree

https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
解题思路:用preorder方法

代码:
class Solution {
public int maxDepth(TreeNode root) {

    if(root == null) return 0;
    return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}

}

你可能感兴趣的:(104. Maximum Depth of Binary Tree)