solution for symmetric trees