We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 19c798f commit c104791Copy full SHA for c104791
0____剑指offer/tree/55.tree_is_balance/tree.cpp
@@ -0,0 +1,27 @@
1
+class Solution
2
+{
3
+public:
4
+ bool isBalanced(TreeNode* node,int& legth)
5
+ {
6
+ if (node == NULL)
7
+ return true;
8
+ legth += 1;
9
+ int left = legth;
10
+ int right = legth;
11
+ if (!isBalanced(node->left, left))
12
+ return false;
13
+ if (!isBalanced(node->right, right))
14
15
+ int max = std::max(left, right);
16
+ int min = std::min(left, right);
17
+ if (max - min > 1)
18
19
+ legth = max;
20
21
+ }
22
+ bool isBalanced(TreeNode* root)
23
24
+ int legth = 0;
25
+ return isBalanced(root, legth);
26
27
+};
0 commit comments