Optimize solution to do early return if subtree is unbalanced