Count Items Matching a Rule LeetCode solution in Java

1
class Solution {
2
public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
3
int res = 0;
4

5
for (int i = 0; i < items.size(); i++) {
6
if (ruleKey.equals("type") && items.get(i).get(0).equals(ruleValue)) res++;
7
if (ruleKey.equals("color") && items.get(i).get(1).equals(ruleValue)) res++;
8
if (ruleKey.equals("name") && items.get(i).get(2).equals(ruleValue)) res++;
9
}
10

11
return res;
12
}
13
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0