【发布时间】:2012-02-22 18:17:48
【问题描述】:
可能重复:
Easy interview question got harder: given numbers 1..100, find the missing number(s)
Find the missing and duplicate elements in an array in linear time and constant space
我在一个论坛上看到了一个有趣的问题。
您有 100 个从 1 到 100 的元素,但错误地其中一个数字通过重复自身而与另一个数字重叠。 例如。 1,99,3,...,99,100 数组未排序,如何找到重复的数字?
我知道 Hash 可以做到 O(n) 时间和 O(n) 空间,我需要 O(1) 空间。
【问题讨论】:
-
为什么你接受了错误的答案? (不是 O(1) 空间)
标签: algorithm