Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. public int countLeftNodes() {
  2.     return countLeftNodes( overallRoot );
  3. }
  4. private int countLeftNodes( IntTreeNode root ) {
  5. // if no child nodes to check
  6.     if( root == null ) {
  7.         return 0;
  8.     }
  9. // if left is present: add 1 to count, check left node, check sibling
  10. if( root.left != null ) {
  11. return 1 + countLeftNodes( root.left ) + countLeftNodes( root.right );
  12. }
  13. // if no left child node, check the right
  14. return countLeftNodes( root.right );
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement