leetcode-104-二叉树的最大深度

//递归,不用helper

/**

 * Definition for a binary tree node.

 * struct TreeNode {

 *     int val;

 *     TreeNode *left;

 *     TreeNode *right;

 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}

 * };

 */

class Solution {

public:

    int maxDepth(TreeNode* root) {

        if (!root) return 0;

        else return max(maxDepth(root->left), maxDepth(root->right))+1;

    }

};

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2021-04-12
  • 2021-11-09
  • 2021-09-13
猜你喜欢
  • 2021-07-21
  • 2021-08-31
  • 2021-09-23
  • 2021-11-27
  • 2022-01-25
  • 2021-07-14
  • 2021-09-15
相关资源
相似解决方案