improve lc sametree (iterative solution)