eliminate the iteration sol
stict to the recursive sol and add early termination
sol of q110