|
@@ -1,8 +1,54 @@
|
1
|
1
|
package com.zipcodewilmington.looplabs;
|
2
|
2
|
|
|
3
|
+import java.util.ArrayList;
|
|
4
|
+import java.util.Arrays;
|
|
5
|
+import java.util.HashMap;
|
|
6
|
+
|
3
|
7
|
/**
|
4
|
8
|
* Created by leon on 1/29/18.
|
5
|
9
|
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
|
6
|
10
|
*/
|
7
|
11
|
public final class IntegerDuplicateDeleter extends DuplicateDeleter<Integer> {
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+ public IntegerDuplicateDeleter(Integer[] intArray) {
|
|
15
|
+ super(intArray);
|
|
16
|
+ }
|
|
17
|
+
|
|
18
|
+ //removes all values in the array which occur exactly the specified number of times.
|
|
19
|
+ @Override
|
|
20
|
+ public Integer[] removeDuplicates(int maxNumberOfDuplications) {
|
|
21
|
+ ArrayList<Integer> list = new ArrayList<>();
|
|
22
|
+ for(Integer i:array){
|
|
23
|
+ if(countDupes(i)<maxNumberOfDuplications){
|
|
24
|
+ list.add(i);
|
|
25
|
+ }
|
|
26
|
+ }
|
|
27
|
+ Integer[] result = new Integer[list.size()];
|
|
28
|
+ return list.toArray(result);
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ //removes all values in the array which occur at least the specified number of times.
|
|
32
|
+ @Override
|
|
33
|
+ public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
|
|
34
|
+ Integer[] result = new Integer[array.length];
|
|
35
|
+ int count = 0;
|
|
36
|
+ for (int i = 0; i < array.length; i++) {
|
|
37
|
+ if(countDupes(array[i])!=exactNumberOfDuplications){
|
|
38
|
+ result[count]=array[i];
|
|
39
|
+ count++;
|
|
40
|
+ }
|
|
41
|
+ }
|
|
42
|
+ return Arrays.copyOfRange(result,0,count);
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ public int countDupes(Integer integer){
|
|
46
|
+ int count = 0;
|
|
47
|
+ for(Integer i: array){
|
|
48
|
+ if(i==integer){
|
|
49
|
+ count++;
|
|
50
|
+ }
|
|
51
|
+ }
|
|
52
|
+ return count;
|
|
53
|
+ }
|
8
|
54
|
}
|