Created
June 2, 2017 14:26
-
-
Save panwarab/fe2482ded770e6e85799a2761e48eddd 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.*; | |
import java.io.*; | |
class Check_Duplicate{ | |
public static void main(String args[]) | |
{ | |
Scanner sc=new Scanner(System.in); | |
int ar[]=getArray(sc.nextLine()); | |
LinkedList<Integer> res=new LinkedList(); | |
Arrays.sort(ar); | |
int sp=0; | |
int dp=0; | |
int len=ar.length; | |
while(true) | |
{ | |
if(sp==dp) | |
{ | |
res.add(ar[sp]); | |
} | |
dp+=1; | |
while(dp<len && ar[sp]==ar[dp]) | |
{ | |
dp++; | |
} | |
if(dp>=len) break; | |
if(ar[sp]!=ar[dp]) | |
{ | |
sp=dp; | |
} | |
} | |
System.out.println(res); | |
} | |
public static int[] getArray(String s) | |
{ | |
String ar[]=s.split(" "); | |
int arr[]=new int[ar.length]; | |
for(int i=0;i<ar.length;i++) | |
{ | |
arr[i]=Integer.parseInt(ar[i]); | |
} | |
return arr; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment