rewrite leetcode max min depth of BT