-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindTheDuplicate.java
More file actions
39 lines (32 loc) · 1.02 KB
/
FindTheDuplicate.java
File metadata and controls
39 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* *****************************************************************************
* Name: Ada Lovelace
* Coursera User ID: 123456
* Last modified: October 16, 1842
**************************************************************************** */
import java.util.Scanner;
public class FindTheDuplicate {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scn.nextInt();
}
boolean[] count = new boolean[n + 1];
int temp = 0;
for (int i = 0; i < n; i++) {
temp = a[i];
if (!count[a[i]]) {
count[a[i]] = true;
}
else {
System.out.println("Duplicate no is:" + temp);
}
}
for (int i = 1; i <= n; i++) {
if (!count[i]) {
System.out.println("Missing no is:" + i);
}
}
}
}