Problem:
given an array in length of N, in which theelements are integers distributed from 1 to N, please judge whether there isduplication quickly.
即一个长度为N的数组,元素取值范围为1到N,要求快速判断是否存在重复元素。
解决方法:
1, 最直观的解法:两两比较数组元素,但是复杂度为o(n2)。
2, 优化版
Problem:
given an array in length of N, in which theelements are integers distributed from 1 to N, please judge whether there isduplication quickly.
即一个长度为N的数组,元素取值范围为1到N,要求快速判断是否存在重复元素。
解决方法:
1, 最直观的解法:两两比较数组元素,但是复杂度为o(n2)。
2, 优化版