-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
36 lines (34 loc) · 802 Bytes
/
Solution.cs
File metadata and controls
36 lines (34 loc) · 802 Bytes
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
public class Solution
{
public int[] FindEvenNumbers(int[] digits)
{
int[] count = new int[10];
int n = digits.Length;
foreach (int d in digits)
{
count[d]++;
}
Backtracking(0, 3, count, 0);
// ret.Sort();
return [.. ret];
}
List<int> ret = [];
void Backtracking(int pos, int n, int[] count, int curr)
{
if (pos >= n)
{
if (curr % 2 == 0) ret.Add(curr);
return;
}
for (int i = 0; i < 10; i++)
{
if (pos == 0 && i == 0) continue;
if (count[i] > 0)
{
count[i]--;
Backtracking(pos + 1, n, count, curr * 10 + i);
count[i]++;
}
}
}
}