Skip to content

Instantly share code, notes, and snippets.

@binjoo
Created October 31, 2012 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binjoo/3987731 to your computer and use it in GitHub Desktop.
Save binjoo/3987731 to your computer and use it in GitHub Desktop.
JAVA:面试题:给定一个一亿长度的数组,数组元素中随机放了0~9,10个数字,要求你统计每个数出现的次数。
public class Test {
public static void main(String[] args) {
int[] a = new int[100000000];
for (int i = 0; i < a.length; i++) {
a[i] = (int) (Math.random() * 10);
}
int[] b = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
long start = System.currentTimeMillis();
for (int i = 0; i < a.length; i++) {
b[a[i]] += 1;
}
long end = System.currentTimeMillis();
System.out.println(end - start + " ms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment