refer to others' elegant algorithm,learn a lot