Sollicitatievraag bij Skillnet Solutions

Find duplicate Elements from array And print the array removing duplicates

Antwoord op sollicitatievraag

Anoniem

15 aug 2019

void removeDups(int[] arr, int n) { // Hash map will store the elements which has appeared previously. HashMap mp = new HashMap(); for (int i = 0; i < n; ++i) { // Print the element if it is not there in the hash map if (mp.get(arr[i]) == null) System.out.print(arr[i] + " "); // Insert the element in the hash map mp.put(arr[i], true); } }

3