1. 题目

Leetcode#110. 平衡二叉树,C++实现

2. 方法一

2.1. 代码

class Solution {
    bool result=true;
public:
    bool isBalanced(TreeNode* root) {
        Max_depth(root);
        return result;
    }
    int Max_depth(TreeNode* head)
    {
        if(head==NULL) return 0;
        int left=Max_depth(head->left);
        int right=Max_depth(head->right);
        if(abs(left-right)>1)
            result=false;
        return max(left,right)+1;
    }
};

2.2. 结果

Leetcode#110. 平衡二叉树,C++实现

相关文章:

  • 2021-07-23
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
猜你喜欢
  • 2021-05-28
  • 2021-07-14
  • 2021-10-29
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
相关资源
相似解决方案