Count Items Matching a Rule LeetCode solution in Java
1class Solution {2public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {3int res = 0;45for (int i = 0; i < items.size(); i++) {6if (ruleKey.equals("type") && items.get(i).get(0).equals(ruleValue)) res++;7if (ruleKey.equals("color") && items.get(i).get(1).equals(ruleValue)) res++;8if (ruleKey.equals("name") && items.get(i).get(2).equals(ruleValue)) res++;9}1011return res;12}13}