Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int countLeftNodes() {
- return countLeftNodes( overallRoot );
- }
- private int countLeftNodes( IntTreeNode root ) {
- // if no child nodes to check
- if( root == null ) {
- return 0;
- }
- // if left is present: add 1 to count, check left node, check sibling
- if( root.left != null ) {
- return 1 + countLeftNodes( root.left ) + countLeftNodes( root.right );
- }
- // if no left child node, check the right
- return countLeftNodes( root.right );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement