Skip to content

Instantly share code, notes, and snippets.

@panwarab
Last active September 15, 2018 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panwarab/3e18c92656e6c4a08686a86fa9b20839 to your computer and use it in GitHub Desktop.
Save panwarab/3e18c92656e6c4a08686a86fa9b20839 to your computer and use it in GitHub Desktop.
package strings;
/*
import java.util.*;
class Distinct {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
boolean[] duplicates = new boolean[128];
String str = sc.nextLine();
String res = "";
for (int i = 0; i < str.length(); i++) {
//use this to get ASCII of any character
int e = (int) str.charAt(i);
duplicates[e] = true;
}
*/
/**
* Now, Iterate duplicates array
* an element will register as true only one time and will be printed only one time, thanks to mapping
* so, append such elements to your String res and print the result
*//*
for (int i = 0; i < 128; i++) {
if (duplicates[i]) {
// get the character back from ascii encoding
res += (char) i;
}
}
System.out.println(res);
}
}
*/
import java.util.*;
class duplicate{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
String w="";
for(int i=0;i<arr.length;i++)
{
String k=arr[i]+"";
if(w.indexOf(k)==-1)
w=w+k+" ";
}
System.out.println(w);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment