Joshua Chung 6 anni fa
parent
commit
c739864a77
2 ha cambiato i file con 107 aggiunte e 3 eliminazioni
  1. 54
    1
      IntegerDuplicateDeleter.java
  2. 53
    2
      StringDuplicateDeleter.java

+ 54
- 1
IntegerDuplicateDeleter.java Vedi File

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

+ 53
- 2
StringDuplicateDeleter.java Vedi File

@@ -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
 }