Last active
August 24, 2017 22:24
-
-
Save micylt/d7b9cd33ee5abf40a9aa to your computer and use it in GitHub Desktop.
returns the number of left children in the tree. A left child is a node that appears as the root of the left-hand subtree of another node. An empty tree has 0 left nodes. For example, the following tree has four left children (the nodes storing the values 5, 1, 4, and 7):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int countLeftNodes() { | |
return countLeftNodes(this.overallRoot); | |
} | |
private int countLeftNodes(IntTreeNode overallRoot) { | |
if (overallRoot != null) { | |
if (overallRoot.left != null) { | |
return 1 + countLeftNodes(overallRoot.left) + countLeftNodes(overallRoot.right); | |
} else { | |
return countLeftNodes(overallRoot.right); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment