-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFinding3DigitEvenNumbers2094.java
More file actions
33 lines (31 loc) · 1.09 KB
/
Finding3DigitEvenNumbers2094.java
File metadata and controls
33 lines (31 loc) · 1.09 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
import java.util.Set;
import java.util.HashSet;
public class Finding3DigitEvenNumbers2094 {
public static int[] findEvenNumbers(int[] digits) {
Set<Integer> res = new HashSet<>();
int[] count = new int[10];
for (int digit : digits) {
count[digit]++;
}
for (int i = 1; i <= 9; i++) {
for (int j = 0; j <= 9; j++) {
for (int k = 0; k <= 8; k += 2) {
int[] tempcount = count.clone();
tempcount[i]--;
tempcount[j]--;
tempcount[k]--;
if (tempcount[i] >= 0 && tempcount[j] >= 0 && tempcount[k] >= 0) {
int num = i * 100 + j * 10 + k;
res.add(num);
}
}
}
}
return res.stream().mapToInt(Integer::intValue).sorted().toArray();
}
public static void main(String[] args) {
int[] digits = { 2, 1, 3, 0 };
findEvenNumbers(digits);
// Output: [102, 120, 132, 210, 230, 302, 320, 402, 420]
}
}