Created
June 18, 2017 17:49
-
-
Save thmain/1fec80ad26bc0c04a988315deda19d5d 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; | |
public class CheckDuplicatesUsingSorting { | |
public void hasDuplicatesUsingSorting(int [] arrA) { | |
Arrays.sort(arrA); | |
for (int i = 0; i < arrA.length-1; i++) { | |
if(arrA[i]==arrA[i+1]){ | |
System.out.println("Array has duplicates : " + arrA[i]); | |
} | |
} | |
} | |
public static void main(String[] args) { | |
int a [] = {1, 6, 5, 2, 3, 3, 2}; | |
new CheckDuplicatesUsingSorting().hasDuplicatesUsingSorting(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment