|
@@ -1,8 +1,101 @@
|
1
|
1
|
package com.zipcodewilmington.looplabs;
|
2
|
2
|
|
|
3
|
+import java.util.Arrays;
|
|
4
|
+
|
3
|
5
|
/**
|
4
|
6
|
* Created by leon on 1/29/18.
|
5
|
7
|
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
|
6
|
8
|
*/
|
7
|
9
|
public final class IntegerDuplicateDeleter extends DuplicateDeleter<Integer> {
|
8
|
|
-}
|
|
10
|
+
|
|
11
|
+ public IntegerDuplicateDeleter(Integer[] intArray) {
|
|
12
|
+ super(intArray);
|
|
13
|
+ }
|
|
14
|
+
|
|
15
|
+ @Override
|
|
16
|
+ public Integer[] removeDuplicates(int maxNumberOfDuplications) {
|
|
17
|
+
|
|
18
|
+ Integer [] result = new Integer[array.length];
|
|
19
|
+ int count = 0;
|
|
20
|
+ for (int i = 0; i < array.length ; i++) {
|
|
21
|
+ if(itemCount(array[i]) < maxNumberOfDuplications){
|
|
22
|
+ result[count] = array[i];
|
|
23
|
+ count++;}
|
|
24
|
+ }
|
|
25
|
+ return Arrays.copyOfRange(result,0,count);
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+// Integer[] arr = Arrays.copyOf(array,array.length);
|
|
29
|
+// StringBuilder stringBuilder = new StringBuilder();
|
|
30
|
+//
|
|
31
|
+// for (int i = 0; i < arr.length ; i++) {
|
|
32
|
+// int count = 1;
|
|
33
|
+// for (int j = 0; j < arr.length; j++) {
|
|
34
|
+// if (arr[j].equals(arr[i])) {
|
|
35
|
+// count++;
|
|
36
|
+// }
|
|
37
|
+// }
|
|
38
|
+// if (count <= maxNumberOfDuplications)
|
|
39
|
+// stringBuilder.append(arr[i]).append("/");
|
|
40
|
+// }
|
|
41
|
+// if(!stringBuilder.toString().equals("")){
|
|
42
|
+// arr =getNewArr(stringBuilder);
|
|
43
|
+// }else{
|
|
44
|
+// arr = new Integer[0];
|
|
45
|
+// }
|
|
46
|
+// return arr;
|
|
47
|
+// }
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+ private int itemCount(int item) {
|
|
51
|
+ int counter = 0;
|
|
52
|
+ for (int items : array) {
|
|
53
|
+ if (items == item)
|
|
54
|
+ counter++;
|
|
55
|
+ }
|
|
56
|
+ return counter;
|
|
57
|
+ }
|
|
58
|
+// private Integer[] getNewArr(StringBuilder stringBuilder) {
|
|
59
|
+// Integer [] arr;
|
|
60
|
+// String [] strings = stringBuilder.toString().split("/");
|
|
61
|
+// arr = new Integer[strings.length];
|
|
62
|
+// for (int i = 0; i < arr.length; i++)
|
|
63
|
+// arr[i] = Integer.valueOf(strings[i]);
|
|
64
|
+// return arr;
|
|
65
|
+// }
|
|
66
|
+
|
|
67
|
+ @Override
|
|
68
|
+ public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
|
|
69
|
+
|
|
70
|
+ Integer [] result = new Integer[array.length];
|
|
71
|
+ int count = 0;
|
|
72
|
+ for (int i = 0; i < array.length ; i++) {
|
|
73
|
+ if(itemCount(array[i]) != exactNumberOfDuplications){
|
|
74
|
+ result[count] = array[i];
|
|
75
|
+ count++;
|
|
76
|
+ }
|
|
77
|
+ }
|
|
78
|
+ return Arrays.copyOfRange(result,0,count);
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+// StringBuilder stringBuilder = new StringBuilder();
|
|
83
|
+// Integer [] arr = Arrays.copyOf(array,array.length);
|
|
84
|
+// for (int i = 0; i < arr.length; i++) {
|
|
85
|
+// int count = 0;
|
|
86
|
+// for (int j = 0; j < arr.length; j++) {
|
|
87
|
+// if (arr[j].equals(arr[i])) {
|
|
88
|
+// count++;
|
|
89
|
+// }
|
|
90
|
+// }
|
|
91
|
+// if (count != exactNumberOfDuplications)
|
|
92
|
+// stringBuilder.append(arr[i]).append("/");
|
|
93
|
+// }
|
|
94
|
+// if(!stringBuilder.toString().equals("")){
|
|
95
|
+// arr =getNewArr(stringBuilder);
|
|
96
|
+// }else{
|
|
97
|
+// arr = new Integer[0];
|
|
98
|
+// }
|
|
99
|
+// return arr;
|
|
100
|
+ }
|
|
101
|
+
|