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;
    }
};
相关推荐
做人求其滴3 天前
面试经典 150 题 380 274
c++·算法·面试·职场和发展·力扣
Lsk_Smion5 天前
Hot100(开刷) 之 LRU(最近最少使用)缓存
力扣
玛卡巴卡ldf6 天前
【LeetCode 手撕算法】(多维动态规划)不同路径、最小路径和、最长回文子串、最长公共子序列、编辑距离
java·数据结构·算法·leetcode·动态规划·力扣
旖-旎9 天前
深搜练习(单词搜索)(12)
c++·算法·深度优先·力扣
玛卡巴卡ldf10 天前
【LeetCode 手撕算法】(动态规划)爬楼梯、杨辉三角、打家劫舍、完全平方数、零钱兑换、单词拆分、最长递增子序列、乘积最大子数组、分割等和子集
java·数据结构·算法·leetcode·动态规划·力扣
玛卡巴卡ldf12 天前
【LeetCode 手撕算法】(栈)有效括号、最小栈、字符串解码、每日温度、柱状图最大矩形
java·数据结构·算法·leetcode·力扣
小辉同志15 天前
62. 不同路径
c++·力扣·多维动态规划
玛卡巴卡ldf16 天前
【LeetCode 手撕算法】(回溯)全排列DFS、子集、电话号码字母组合 九键、组合总和、括号生成、单词搜索、分割回文数
java·算法·leetcode·力扣
mask哥17 天前
15种算法模式java实现详解
java·算法·力扣
旖-旎20 天前
深搜练习(N皇后)(10)
c++·算法·深度优先·力扣