Skip to content

Instantly share code, notes, and snippets.

@shaobos
Last active August 29, 2015 14:05
Show Gist options
  • Save shaobos/af438e681eb19b624f0b to your computer and use it in GitHub Desktop.
Save shaobos/af438e681eb19b624f0b to your computer and use it in GitHub Desktop.
int chec_balance (TreeNode* node) {
if (node == NULL) {
return 0;
}
int l = check_balance(node->left);
int r = ...
if (l == -1 || r== -1) {
return -1;
}
if (abs(l-r) > 1) {
return -1;
} else {
return max(l, r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment