Advertisement
kamandos

HW3

Jun 29th, 2022
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. public class Main
  2. public static int[] removeDuplicates(int[] arr) {
  3.  
  4.     int end = arr.length;
  5.  
  6.     for (int i = 0; i < end; i++) {
  7.         for (int j = i + 1; j < end; j++) {
  8.             if (arr[i] == arr[j]) {                  
  9.                 int shiftLeft = j;
  10.                 for (int k = j+1; k < end; k++, shiftLeft++) {
  11.                     arr[shiftLeft] = arr[k];
  12.                 }
  13.                 end--;
  14.                 j--;
  15.             }
  16.         }
  17.     }
  18.  
  19.     int[] whitelist = new int[end];
  20.     for(int i = 0; i < end; i++){
  21.         whitelist[i] = arr[i];
  22.     }
  23.     return whitelist;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement