class Solution {
public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
int result = 0;
if (ruleKey.equals("type")) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).get(0).equals(ruleValue)) result++;
}
}
if (ruleKey.equals("color")) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).get(1).equals(ruleValue)) result++;
}
}
if (ruleKey.equals("name")) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).get(2).equals(ruleValue)) result++;
}
}
return result;
}
}
leetcode 1773. 统计匹配检索规则的物品数量
最新推荐文章于 2025-04-09 03:15:00 发布