image_2021-10-15_03-31-56.png
48.9 KB
#N1773 Count Items Matching a Rule
problem link=>https://leetcode.com/problems/count-items-matching-a-rule/
#solution
problem link=>https://leetcode.com/problems/count-items-matching-a-rule/
#solution
class Solution {
public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
int key, count=0;
if(ruleKey.equals("type"))
key=0;
else if(ruleKey.equals("color"))
key=1;
else
key=2;
for(int i=0; i<items.size(); i++){
if(items.get(i).get(key).equals(ruleValue))
count++;
}
return count;
}
}