Last active
September 15, 2018 08:52
-
-
Save panwarab/3e18c92656e6c4a08686a86fa9b20839 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
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