Skip to content

Commit 313c3f7

Browse files
committed
Added solution to Finding-missing-element in java
1 parent 969e000 commit 313c3f7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.*;
2+
public class FindingMissingElement {
3+
4+
/**
5+
*The difference in the sum of the two arrays will give us the desired value
6+
*/
7+
static int find_missing(int a[],int b[])
8+
{
9+
int sum=0;
10+
for(int i:a)
11+
sum+=i;
12+
for(int i:b)
13+
sum-=i;
14+
return sum;
15+
}
16+
public static void main(String[] args) {
17+
int[] arr={1,3,5,6,2,5,6,8,9,23,45,67,87};
18+
int[] shuffled_ar={1,2,5,6,8,9,3,45,87,6,67,5};
19+
System.out.println("The missing value is:"+find_missing(arr,shuffled_ar));
20+
21+
22+
}
23+
24+
}

0 commit comments

Comments
 (0)