IT常识
技术 Python PHP JavaScript IOS Android Java 数据库 资源 公众号 代码片段 github
  • IT常识
  • web服务器

LeetCode之104. Maximum Depth of Binary Tree

Posted 2020-08-15

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode之104. Maximum Depth of Binary Tree相关的知识,希望对你有一定的参考价值。

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

 

递归遍历即可

 

AC代码:

/**
 * Definition for a binary tree node.
 * 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;
        return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
    }
}

 

题目来源: https://leetcode.com/problems/maximum-depth-of-binary-tree/

以上是关于LeetCode之104. Maximum Depth of Binary Tree的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 104. Maximum Depth of Binary Tree

LeetCode104. Maximum Depth of Binary Tree

leetcode104-Maximum Depth of Binary Tree

Leetcode刷题记录[python]——104 Maximum Depth of Binary Tree

LeetCode 104. Maximum Depth of Binary Tree

[Lintcode]97. Maximum Depth of Binary Tree/[Leetcode]104. Maximum Depth of Binary Tree

(c)2006-2024 SYSTEM All Rights Reserved IT常识