code style optimization
recursive solution