1773.统计匹配检索规则的物品数量
链接:1773.统计匹配检索规则的物品数量
难度:Easy
标签:数组、字符串
简介:统计并返回 匹配检索规则的物品数量 。
题解 1 - cpp
- 编辑时间:2022-10-29
- 执行用时:68ms
- 内存消耗:30.2MB
- 编程语言:cpp
- 解法介绍:模拟。
class Solution {
public:
int countMatches(vector<vector<string>>& items, string ruleKey, string ruleValue) {
return accumulate(items.begin(), items.end(), 0, [&](int sum, vector<string> &s){
int idx = ruleKey == "type" ? 0 : ruleKey == "color" ? 1 : 2;
if (s[idx] == ruleValue) sum += 1;
return sum;
});
}
};