two solutions for balanced binary tree