refer to others' elegant algorithm, learn