Created
June 18, 2017 17:50
-
-
Save thmain/37676c716472619b521cb13e09ffa791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.HashMap; | |
public class CheckDuplicatesUsingHashMap { | |
public void hasDuplicatesUsingMap(int [] arrA){ | |
HashMap<Integer, Integer> map = new HashMap<>(); | |
for (int i = 0; i <arrA.length ; i++) { | |
if(map.containsKey(arrA[i])){ | |
System.out.println("Array has duplicates : " + Math.abs(arrA[i])); | |
}else{ | |
map.put(arrA[i], 1); | |
} | |
} | |
} | |
public static void main(String[] args) { | |
int a [] = {1, 6, 5, 2, 3, 3, 2}; | |
new CheckDuplicatesUsingHashMap().hasDuplicatesUsingMap(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment