fix 1th, 2th algorithm, get a better complexity