IntegerDuplicateDeleter.java 1.6KB

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