剑指 Offer 55 - I 二叉树的深度

标签: 剑指 Offer 发布于:2022-02-27 16:53:22 编辑于:2022-02-27 16:56:21 浏览量:833

概述

https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/

https://leetcode.com/problems/maximum-depth-of-binary-tree/

递归法

class Solution {
public:
    int maxDepth(TreeNode* root) {
        if (!root) return 0;
        return 1 + max(maxDepth(root->left), maxDepth(root->right));
    }
};

未经允许,禁止转载,本文源站链接:https://iamazing.cn/