used more than one hour to solve this problem
be careful, care more about the time complexity