|
@@ -1,6 +1,57 @@
|
1
|
1
|
|
2
|
2
|
|
3
|
3
|
public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
|
4
|
|
-
|
5
|
|
-
|
|
4
|
+
|
|
5
|
+ String[] stringArr;
|
|
6
|
+
|
|
7
|
+ public StringDuplicateDeleter(String[] array) {
|
|
8
|
+ super(array);
|
|
9
|
+ }
|
|
10
|
+
|
|
11
|
+ public String[] removeDuplicates(int n){
|
|
12
|
+ String[] newArr = new String[0];
|
|
13
|
+ int count = 0;
|
|
14
|
+ for(String i : array) {
|
|
15
|
+ for(String j : array) {
|
|
16
|
+ if(i == j) {
|
|
17
|
+ count++;
|
|
18
|
+ }
|
|
19
|
+ }
|
|
20
|
+ if(count < n) {
|
|
21
|
+ String[] temp = new String[newArr.length + 1];
|
|
22
|
+ for(int k = 0; k < newArr.length; k++) {
|
|
23
|
+ temp[k] = newArr[k];
|
|
24
|
+ }
|
|
25
|
+ temp[temp.length - 1] = i;
|
|
26
|
+ newArr = temp;
|
|
27
|
+ }
|
|
28
|
+ }
|
|
29
|
+ String[] newArr2 = new String[]{};
|
|
30
|
+ if(newArr.length == 1 && newArr[0] == "") {
|
|
31
|
+ return newArr2;
|
|
32
|
+ }
|
|
33
|
+ else{ return newArr;
|
|
34
|
+ }
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ public String[] removeDuplicatesExactly(int n) {
|
|
38
|
+ String[] newArr = new String[0];
|
|
39
|
+ int count = 0;
|
|
40
|
+ for(String i : array) {
|
|
41
|
+ for(String j : array) {
|
|
42
|
+ if(j == i) {
|
|
43
|
+ count++;
|
|
44
|
+ }
|
|
45
|
+ }
|
|
46
|
+ if(count != n) {
|
|
47
|
+ String[] temp = new String[newArr.length + 1];
|
|
48
|
+ for(int k = 0; k < newArr.length; k++) {
|
|
49
|
+ temp[k] = newArr[k];
|
|
50
|
+ }
|
|
51
|
+ temp[temp.length - 1] = i;
|
|
52
|
+ newArr = temp;
|
|
53
|
+ }
|
|
54
|
+ }
|
|
55
|
+ return newArr;
|
|
56
|
+ }
|
6
|
57
|
}
|