diff --git a/src/main/java/com/fishercoder/solutions/_1773.java b/src/main/java/com/fishercoder/solutions/_1773.java index 306b2642aa..9f1bb563b0 100644 --- a/src/main/java/com/fishercoder/solutions/_1773.java +++ b/src/main/java/com/fishercoder/solutions/_1773.java @@ -5,13 +5,19 @@ public class _1773 { public static class Solution1 { public int countMatches(List> items, String ruleKey, String ruleValue) { + int index =0; + if(ruleKey.equals("color")){ + index =1; + } + if(ruleKey.equals("name")){ + index =2; + } + int match = 0; + + for (List item : items) { - if (ruleKey.equals("type") && item.get(0).equals(ruleValue)) { - match++; - } else if (ruleKey.equals("color") && item.get(1).equals(ruleValue)) { - match++; - } else if (ruleKey.equals("name") && item.get(2).equals(ruleValue)) { + if(item.get(index).equals(ruleValue)){ match++; } }