123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import java.util.*;
-
- public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer>{
- public IntegerDuplicateDeleter(Integer[] array){
- super(array);
- }
-
- public Integer[] removeDuplicates(int maxNumberOfDuplications){
- Integer[] answer = new Integer[array.length];
- int answerIndex = 0;
- for(int i = 0; i < array.length; i++){
- Integer ocurrances = getAppearances(array[i]);
- if(ocurrances < maxNumberOfDuplications) {
- answer[answerIndex] = array[i];
- answerIndex++;
- }
- }
-
- Integer[] realAnswer = Arrays.copyOf(answer, answerIndex);
-
- return realAnswer;
- }
-
- public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications){
- Integer[] answer = new Integer[array.length];
- int answerIndex = 0;
- for(int i = 0; i < array.length; i++){
- Integer ocurrances = getAppearances(array[i]);
- if(ocurrances < exactNumberOfDuplications || ocurrances > exactNumberOfDuplications) {
- answer[answerIndex] = array[i];
- answerIndex++;
- }
- }
-
- Integer[] realAnswer = Arrays.copyOf(answer, answerIndex);
-
- return realAnswer;
-
-
- }
-
- public int getAppearances(int x){
- int counter = 0;
- for(int element : array ){
- if(element == x){
- counter++;
- }
- }
- return counter;
- }
-
- }
-
|