Просмотр исходного кода

finished GetNumberOfOccurrencesTest

Luis Romero 6 лет назад
Родитель
Сommit
49522bf904
1 измененных файлов: 31 добавлений и 3 удалений
  1. 31
    3
      src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java

+ 31
- 3
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java Просмотреть файл

2
 
2
 
3
 import java.util.ArrayList;
3
 import java.util.ArrayList;
4
 import java.util.Arrays;
4
 import java.util.Arrays;
5
+import java.util.HashMap;
5
 
6
 
6
 /**
7
 /**
7
  * Created by leon on 3/6/18.
8
  * Created by leon on 3/6/18.
33
     }
34
     }
34
 
35
 
35
     public int getNumberOfOccurrences(E valueToEvaluate) {
36
     public int getNumberOfOccurrences(E valueToEvaluate) {
36
-        return 0;
37
+        int count = 0;
38
+        for (E element : inputArray) {
39
+            if (element == valueToEvaluate) {
40
+                count++;
41
+            }
42
+        }
43
+        return count;
37
     }
44
     }
38
 
45
 
39
-
40
-
46
+//    public int getMostCommonFromMerge(E valueToEvaluate) {
47
+//
48
+//        Object mostCommonNum = null;
49
+//        int mostOccurrences = 0;
50
+//
51
+//        HashMap<Object, Integer> hashMap = new HashMap<>();
52
+//
53
+//        for (Object object : objectArray) {
54
+//            if (!hashMap.containsKey(object)) {
55
+//                hashMap.put(object, 1);
56
+//            } else {
57
+//                hashMap.put(object, hashMap.get(object) + 1);
58
+//            }
59
+//
60
+//            if (hashMap.get(object) > mostOccurrences) {
61
+//                mostCommonNum = object;
62
+//                mostOccurrences = hashMap.get(object);
63
+//            }
64
+//        }
65
+//
66
+//        System.out.println(mostCommonNum);
67
+//        return mostCommonNum;
68
+//    }
41
 
69
 
42
 }
70
 }