Solve RebuildBSTFromPreorder.