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

Tag: 剑指-Offer Posted on 2022-02-27 16:53:22 Edited on 2022-02-27 16:56:21 Views: 156

概述

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/