Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int[] removeDuplicates(int[] input) {
- int arrayLength = input.length;
- Integer[] nums = new Integer[arrayLength];
- for (int el : input) {
- if (!doesElementExistInArray(el, nums)) {
- addToArray(el, nums);
- }
- }
- int count = 0;
- for(int i = 0; i < nums.length; i++) {
- if(nums[i] == null)
- continue;
- count++;
- }
- int[] array = new int[count];
- for(int i = 0; i < count; i++) {
- array[i] = nums[i];
- }
- return array;
- }
- public static boolean doesElementExistInArray(int num, Integer[] arr){
- for (int i = 0; i < arr.length; i++) {
- if (arr[i] != null)
- if(arr[i] == num)
- return true;
- }
- return false;
- }
- public static Integer[] addToArray(int num, Integer[] arr){
- for (int i = 0; i < arr.length; i++){
- if (arr[i] != null)
- continue;
- arr[i] = num;
- return arr;
- }
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement