File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -4,29 +4,27 @@ public static void main(String[] args){
4
4
Scanner sc = new Scanner (System .in );
5
5
6
6
int n = sc .nextInt ();
7
- int arr [] = new int [n ];
8
- int temp [] = new int [n ];
7
+ int a [] = new int [n ];
9
8
10
- //input array
11
- for (int i =0 ; i <arr .length ; i ++){
12
- arr [i ]=sc .nextInt ();
9
+ for (int i =0 ; i <a .length ; i ++){
10
+ a [i ]=sc .nextInt ();
13
11
}
14
12
15
- //iterate in array & check if found duplicate then store duplicate in temp array
16
- for (int i =0 ; i <arr .length ; i ++){
17
- for (int j =i +1 ; j <arr .length ; j ++){
18
- if (arr [i ]==arr [j ]){
19
- temp [i ]=arr [i ];
13
+ int temp [] = new int [n ];
14
+
15
+ for (int i =0 ; i <a .length ; i ++){
16
+ for (int j =i +1 ; j <a .length ; j ++){
17
+ if (a [i ]==a [j ]){
18
+ temp [i ]=a [j ];
20
19
}
21
20
}
22
21
}
23
-
24
- //print only single element (not duplicate)
25
- for (int i =0 ; i <n ; i ++){
26
- int res = arr [i ]-temp [i ];
22
+ for (int i =0 ; i <a .length ; i ++){
23
+ int res = a [i ]-temp [i ];
27
24
if (res !=0 ){
28
25
System .out .print (res +" " );
29
26
}
30
27
}
28
+
31
29
}
32
30
}
You can’t perform that action at this time.
0 commit comments