Skip to content

Commit f0d703c

Browse files
authored
Create Find All Non Repeating Element in Array.java
1 parent 231aec0 commit f0d703c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.util.Scanner;
2+
public class main{
3+
public static void main(String[] args){
4+
Scanner sc = new Scanner(System.in);
5+
6+
int n = sc.nextInt();
7+
int a[] = new int[n];
8+
for(int i=0; i<n; i++){
9+
a[i]=sc.nextInt();
10+
}
11+
boolean visit[] = new boolean[n];
12+
int temp[] = new int[n];
13+
14+
for(int i=0; i<n; i++){
15+
for(int j=i+1; j<n; j++){
16+
if(a[i]==a[j] && !visit[j]){
17+
temp[i]=a[i];
18+
visit[j]=true;
19+
break;
20+
}
21+
}
22+
}
23+
24+
for(int i=0; i<n; i++){
25+
int res = a[i]-temp[i];
26+
if(res==0){
27+
continue;
28+
}
29+
else{
30+
System.out.print(res+" ");
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)