另一种算法求职面试算法

由网友(素颜小可爱)分享简介:因此​​,这里的问题:So here is the question:假设你有10万的整数取值范围从1到100万。请理清整数。时间复杂度应为O(n)。Suppose you have 100 thousand integers which ranges from 1 to 1 million. Please sor...

因此​​,这里的问题:

So here is the question:

假设你有10万的整数取值范围从1到100万。请理清整数。时间复杂度应为O(n)。

Suppose you have 100 thousand integers which ranges from 1 to 1 million. Please sort out the integers. The time complexity should be O(n).

如果谁分享他或她的想法是非常AP preciated。

Anybody who shares his or her ideas is well appreciated.

推荐答案

听起来像是一个简单的计数排序。

Sounds like a straightforward counting sort.

后备存储器阵列的尺寸为100万 在初始化所有的数组值0 通过整数环。对于每一个整数i递增[i]发表之一。 通过阵列走并打印每个数字我的[我]次输出排序序列。

空间是恒定的。运行时间为O(n)。

Space is constant. Runtime is O(n).

阅读全文

相关推荐

最新文章