37.二叉树的最大深度

1.递归的理解

2.代码

cpp 复制代码
class Solution {
public:
    int maxDepth(TreeNode* root) {
        if(root==NULL){
            return 0;
        }
        int leftdepth = maxDepth(root->left);
        int rightdepth = maxDepth(root->right);
        int realdepth = max(leftdepth,rightdepth)+1;//1为根节点
        return realdepth;
    }
};
相关推荐
玛卡巴卡ldf15 天前
【LeetCode 手撕算法】(细节知识点总结)
java·数据结构·算法·leetcode·力扣
旖-旎1 个月前
《LeetCode 417 太平洋大西洋水流问题 FloodFill DFS 解法》
c++·算法·深度优先·力扣·floodfill
旖-旎1 个月前
《LeetCode 130 被围绕的区域 FloodFill DFS 解法》
c++·算法·深度优先·力扣·floodfill
旖-旎1 个月前
《LeetCode 695 岛屿的最大面积 FloodFill DFS 解法》
c++·算法·力扣·深度优先遍历·floodfill
旖-旎1 个月前
《LeetCode 200 FloodFill 岛屿数量DFS解法》
c++·算法·深度优先·力扣·floodfill
旖-旎1 个月前
FloodFill(图像渲染)(1)
c++·算法·深度优先·力扣
帅小伙―苏1 个月前
239. 滑动窗口最大值
python·力扣
语戚2 个月前
力扣 3161. 块放置查询:线段树解法(Java 实现)
java·算法·leetcode·面试·线段树·力扣·
填满你的记忆2 个月前
《动态规划-基础篇》
算法·动态规划·力扣
做人求其滴2 个月前
面试经典 150 题 380 274
c++·算法·面试·职场和发展·力扣