Advertisement
2094. Finding 3-Digit Even Numbers
UnknownView on LeetCode
2094.cs
C#
public class Solution
{
public int[] FindEvenNumbers(int[] digits)
{
List<int> ans = new List<int>();
int[] count = new int[10];
foreach (var digit in digits)
++count[digit];
// Try to construct `abc`.
for (int a = 1; a <= 9; ++a)
{
for (int b = 0; b <= 9; ++b)
{
for (int c = 0; c <= 8; c += 2)
{
if (count[a] > 0 && count[b] > (b == a ? 1 : 0) &&
count[c] > (c == a ? 1 : 0) + (c == b ? 1 : 0))
ans.Add(a * 100 + b * 10 + c);
}
}
}
return ans.ToArray();
}
}Advertisement
Was this solution helpful?