Questions tagged «searching»

9
如何在O(n)时间中找到5个重复值?
假设您有一个大小为的数组,其中包含从到(含)在内的整数,并且正好重复了5个。我需要提出一种算法,该算法可以找到O(n)时间中的重复数。我一生都无法想任何事情。我认为排序最好是O(n \ log n)?然后遍历数组将是O(n),从而导致O(n ^ 2 \ log n)。但是,我不确定是否需要排序,因为我已经看到一些棘手的东西,包括链接列表,队列,堆栈等。1n≥6n≥6n \geq 6111O (n )O (n log n )O (n )O (n 2 log n )n−5n−5n − 5O(n)O(n)O(n)O(nlogn)O(nlog⁡n)O(n\log n)O(n)O(n)O(n)O(n2logn)O(n2log⁡n)O(n^2\log n)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.