Recently saw an interview with Baidu: How to find the number of non-repeating numbers from 250 million integers
Write the following implementation, the time is slightly tight, the idea is slightly coarse, there are errors also please point out. Thank you.
int[] isrepeat = new Int[arr.length]; modified to int[] Isrepeat = new int[250000000];
Need to request the JVM 512M of memory
public static int GetCount (int[] arr) {
int norepeatcount = 0;//number of distinct digits
// int repeatcount = 0;//repeats multiple times
int[] isrepeat = new Int[arr.length];
for (int i:isrepeat) {
isrepeat[i]=0;
}
Read in a number to see if the corresponding flag is 0, if 0,flag 1,count plus 1, if 1, do not process for
(int i = 0; i < arr.length; i++) {
int count = 1;
if (Isrepeat[arr[i]] = = 0) {
Isrepeat[arr[i]] + = count;
} else if (Isrepeat[arr[i] > 0) {
Isrepeat[arr [i]] + = count;
}
}
for (int i:isrepeat) {
if (i = = 1) {
norepeatcount++;//returns the one that appears once
}
// else if (i > 1) {
// repeatcount++;////Returns the number of repeated occurrences // } } return norepeatcount; } public static void Main (string[] args) throws ParseException { int[] arr = {1, 2, 2, 3, 4, 5, 6, 7, 7, 8, 8, 8, 8, 9 , ten, ten}; System.out.println (GetCount (arr)); }