62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.Random;
class T {
public static void main(String[] args) {
int MAX = 100000;
int[] nums = new int[MAX];
Random r = new Random(20080623);
for (int i = 0; i < MAX; i++) {
nums[i] = r.nextInt(MAX);
}
long begin = System.currentTimeMillis();
sort(nums);
long end = System.currentTimeMillis();
System.out.println((end - begin)); // 以这个时间为标准,越小越好。
}
public static int[] sort(int[] nums) {
// 您的排序代码放在这里啦
return nums;
}
}
public static int[] sort(int[] nums) {
int max = nums.length;
int i, j;
int[] temp = new int[max];
for (i = 0; i < max;) {
temp[nums[i++]]++;
}
int pos = 0;
for (i = 0; i < max; ++i) {
for (j = 0; j < temp[i]; ++j) {
nums[pos++] = i;
}
}
return nums;
}