MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / check

Method check

CPP/Trees/BalancedBinarytrees.cpp:15–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13class Solution {
14public:
15 int check(TreeNode* root){
16 if(root==NULL)return 0;
17 int lh=check(root->left);
18 int rh=check(root->right);
19 if(lh==-1 || rh==-1)return -1;
20 if(abs(lh-rh)>1)return -1;
21 return max(lh,rh)+1;
22 }
23
24 bool isBalanced(TreeNode* root) {
25 return check(root)!=-1;

Callers

nothing calls this directly

Calls 2

checkFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected