We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
int checkHeight(TreeNode* root) { if (root == nullptr) { return 0; } int leftHeight = checkHeight(root->left); if (leftHeight == -1) { return -1; } int rightHeight = checkHeight(root->right); if (rightHeight == -1) { return -1; }
if (abs(leftHeight - rightHeight) > 1) { return -1; } else { return max(leftHeight, rightHeight) + 1; }
}
//wrapper function should be checkHeight != -1 ... not checkHeight == -1 bool isBalanced(TreeNode* root) { //return (checkHeight == -1); return (checkHeight != -1); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
int checkHeight(TreeNode* root) {
if (root == nullptr) {
return 0;
}
int leftHeight = checkHeight(root->left);
if (leftHeight == -1) {
return -1;
}
int rightHeight = checkHeight(root->right);
if (rightHeight == -1) {
return -1;
}
}
//wrapper function should be checkHeight != -1 ... not checkHeight == -1
bool isBalanced(TreeNode* root) {
//return (checkHeight == -1);
return (checkHeight != -1);
}
The text was updated successfully, but these errors were encountered: