rewrite leetcode balanced binary tree