12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
-
-
- public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
-
- String[] stringArr;
-
- public StringDuplicateDeleter(String[] array) {
- super(array);
- }
-
- public String[] removeDuplicates(int n){
- String[] newArr = new String[0];
- int count = 0;
- for(String i : array) {
- for(String j : array) {
- if(i == j) {
- count++;
- }
- }
- if(count < n) {
- String[] temp = new String[newArr.length + 1];
- for(int k = 0; k < newArr.length; k++) {
- temp[k] = newArr[k];
- }
- temp[temp.length - 1] = i;
- newArr = temp;
- }
- }
- String[] newArr2 = new String[]{};
- if(newArr.length == 1 && newArr[0] == "") {
- return newArr2;
- }
- else{ return newArr;
- }
- }
-
- public String[] removeDuplicatesExactly(int n) {
- String[] newArr = new String[0];
- int count = 0;
- for(String i : array) {
- for(String j : array) {
- if(j == i) {
- count++;
- }
- }
- if(count != n) {
- String[] temp = new String[newArr.length + 1];
- for(int k = 0; k < newArr.length; k++) {
- temp[k] = newArr[k];
- }
- temp[temp.length - 1] = i;
- newArr = temp;
- }
- }
- return newArr;
- }
- }
|