Created
October 31, 2012 15:39
-
-
Save binjoo/3987731 to your computer and use it in GitHub Desktop.
JAVA:面试题:给定一个一亿长度的数组,数组元素中随机放了0~9,10个数字,要求你统计每个数出现的次数。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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