当前位置:   article > 正文

力扣104 二叉树的最大深度

力扣104 二叉树的最大深度

 This is the address of the question.

   104. 二叉树的最大深度

The key to this question is to find the height of the tree.
Let's show you the code for this question.

If you don't know what the height of the tree is, you can check out my previous blog post.

  1. int maxDepth(struct TreeNode* root) {
  2. if (root == NULL)
  3. return 0;
  4. int leftHeight = maxDepth(root->left);
  5. int rightHeight = maxDepth(root->right);
  6. return leftHeight > rightHeight ? leftHeight + 1 : rightHeight + 1;
  7. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/1021284
推荐阅读
相关标签
  

闽ICP备14008679号