-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path'
More file actions
29 lines (28 loc) · 618 Bytes
/
Copy path'
File metadata and controls
29 lines (28 loc) · 618 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <cstdlib>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
public:
bool isBalanced(TreeNode *root) {
if (root == NULL)
return true;
if (root->left && root->right)
return isBalanced(root->left) && isBalanced(root->right);
if (root->left) {
return root->left->left && !root->left->right;
if (root->left->left || root->left->right)
return false;
else
return true;
}
}
};
int main(int argc, char **argv)
{
return 0;
}