
g1701_1800.s1773_count_items_matching_a_rule.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java17 Show documentation
Show all versions of leetcode-in-java17 Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
package g1701_1800.s1773_count_items_matching_a_rule;
// #Easy #Array #String #2022_04_30_Time_7_ms_(25.91%)_Space_56.9_MB_(35.49%)
import java.util.List;
public class Solution {
public int countMatches(List> items, String ruleKey, String ruleValue) {
int match = 0;
for (List item : items) {
if ((ruleKey.equals("type") && item.get(0).equals(ruleValue))
|| (ruleKey.equals("color") && item.get(1).equals(ruleValue))
|| (ruleKey.equals("name") && item.get(2).equals(ruleValue))) {
match++;
}
}
return match;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy