Efficient way to do this

Each node is accessed multiple times in this implementation. 
A more efficient is to design a getBalancedTreeHeight function which return height of the tree if tree is balanced or return -1 if tree is not balanced.