题解链接
哈希双百c++ - 找出 3 位偶数 - 力扣(LeetCode) (leetcode-cn.com)
class Solution {
int hash[10];
public:
vector<int> findEvenNumbers(vector<int>& digits) {
int x;
for(auto &x:digits)//遍历
{
hash[x]++;//哈希计数
}
int a,b,c;
vector<int>ret;
for(int i=100;i<999;i+=2)//三位偶数
{
a=i%10;b=i/10%10;c=i/100;//取出来个位十位百位
hash[a]--;
hash[b]--;
hash[c]--;
if(hash[a]>=0&&hash[b]>=0&&hash[c]>=0)//如果能组合成
ret.push_back(i);
hash[a]++;//重置便于下一次循环
hash[b]++;
hash[c]++;
}
return ret;
}
};