Skip to content

Instantly share code, notes, and snippets.

@hendisantika
Created January 9, 2019 23:18
Show Gist options
  • Save hendisantika/15c1dc726e3fce7f8c0e8bba6cd6d5f0 to your computer and use it in GitHub Desktop.
Save hendisantika/15c1dc726e3fce7f8c0e8bba6cd6d5f0 to your computer and use it in GitHub Desktop.
package com.hendisantika.test.tes3;
import java.util.HashMap;
import java.util.Map;
/**
* Created by IntelliJ IDEA.
* Project : test-java
* User: hendisantika
* Email: [email protected]
* Telegram : @hendisantika34
* Date: 2019-01-09
* Time: 20:02
* To change this template use File | Settings | File Templates.
*/
public class FindDuplicate {
// Function to print duplicates
public static void printDuplicates(int arr[], int n)
{
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i: arr)
{
if(map.containsKey(i))
{
System.out.println("Duplicate element --> "+ i);
}
else
{
map.put(i, i);
}
}
}
// Driver program
public static void main(String[] args)
{
FindDuplicate duplicate = new FindDuplicate();
// int arr[] = {2, 1, 4, 1, 3};
// int arr[] = {1, 2, 3, 1, 3, 6, 6};
// int arr[] = {11, 21, 13, 11, 31, 16, 61};
int arr[] = {20, 11, 34, 14, 34, 11};
int arr_size = arr.length;
duplicate.printDuplicates(arr, arr_size);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment