|
@@ -1,8 +1,66 @@
|
1
|
1
|
package com.zipcodewilmington.looplabs;
|
2
|
2
|
|
|
3
|
+import java.util.Arrays;
|
|
4
|
+import java.util.stream.Stream;
|
|
5
|
+
|
3
|
6
|
/**
|
4
|
7
|
* Created by leon on 1/29/18.
|
5
|
8
|
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
|
6
|
9
|
*/
|
7
|
10
|
public final class IntegerDuplicateDeleter extends DuplicateDeleter<Integer> {
|
|
11
|
+
|
|
12
|
+ public IntegerDuplicateDeleter(Integer[] intArray) {
|
|
13
|
+ super(intArray);
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ @Override //note: README says to remove values that occur AT LEAST. H/e parameter implies AT MOST.
|
|
17
|
+ public Integer[] removeDuplicates(int maxNumberOfDuplications) {
|
|
18
|
+ Integer[] array2 = Arrays.copyOf(array, array.length);
|
|
19
|
+ StringBuilder sb = new StringBuilder();
|
|
20
|
+ for (int i = 0; i < array2.length; i++) {
|
|
21
|
+ int count = 1;
|
|
22
|
+ for (int j = 0; j < array2.length; j++) {
|
|
23
|
+ if (array2[j].equals(array2[i])) {
|
|
24
|
+ count++;
|
|
25
|
+ }
|
|
26
|
+ }
|
|
27
|
+ if (count <= maxNumberOfDuplications)
|
|
28
|
+ sb.append(array2[i]).append("/");
|
|
29
|
+ }
|
|
30
|
+ if (!sb.toString().equals("")) {
|
|
31
|
+ array2 = getNewArray(sb);
|
|
32
|
+ }
|
|
33
|
+ else { array2 = new Integer[0];}
|
|
34
|
+ return array2;
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ @Override
|
|
38
|
+ public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
|
|
39
|
+ StringBuilder sb = new StringBuilder();
|
|
40
|
+ Integer[] array2 = Arrays.copyOf(array, array.length);
|
|
41
|
+ for (int i = 0; i < array2.length; i++) {
|
|
42
|
+ int count = 0;
|
|
43
|
+ for (int j = 0; j < array2.length; j++) {
|
|
44
|
+ if (array2[j].equals(array2[i])) {
|
|
45
|
+ count++;
|
|
46
|
+ }
|
|
47
|
+ }
|
|
48
|
+ if (count != exactNumberOfDuplications)
|
|
49
|
+ sb.append(array2[i]).append("/");
|
|
50
|
+ }
|
|
51
|
+ if (!sb.toString().equals("")) {
|
|
52
|
+ array2 = getNewArray(sb);
|
|
53
|
+ }
|
|
54
|
+ else { array2 = new Integer[0];}
|
|
55
|
+ return array2;
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ private Integer[] getNewArray(StringBuilder sb) {
|
|
59
|
+ Integer[] array2;
|
|
60
|
+ String[] s = sb.toString().split("/");
|
|
61
|
+ array2 = new Integer[s.length];
|
|
62
|
+ for (int i = 0; i < array2.length; i++)
|
|
63
|
+ array2[i] = Integer.valueOf(s[i]);
|
|
64
|
+ return array2;
|
|
65
|
+ }
|
8
|
66
|
}
|