Skip to content

Instantly share code, notes, and snippets.

@micylt
Last active August 24, 2017 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micylt/321fd1947f3961d9d397 to your computer and use it in GitHub Desktop.
Save micylt/321fd1947f3961d9d397 to your computer and use it in GitHub Desktop.
Counts the number of empty branches within an int tree
public int countEmpty() {
return countEmpty(this.overallRoot);
}
private int countEmpty(IntTreeNode overallRoot) {
if (overallRoot == null) {
return 1;
} else {
return countEmpty(overallRoot.left) + countEmpty(overallRoot.right);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment