File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed 
src/main/java/g1701_1800/s1773_count_items_matching_a_rule Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 11package  g1701_1800 .s1773_count_items_matching_a_rule ;
22
3- // #Easy #Array #String #2022_04_30_Time_7_ms_(25.91%)_Space_56 .9_MB_(35.49 %) 
3+ // #Easy #Array #String #2022_05_02_Time_3_ms_(98.33%)_Space_46 .9_MB_(92.77 %) 
44
55import  java .util .List ;
66
77public  class  Solution  {
88 public  int  countMatches (List <List <String >> items , String  ruleKey , String  ruleValue ) {
9-  int  match  = 0 ;
9+  int  ans  = 0 ;
10+  int  checkRuleNum  = 0 ;
11+  if  (ruleKey .equals ("color" )) {
12+  checkRuleNum  = 1 ;
13+  } else  if  (ruleKey .equals ("name" )) {
14+  checkRuleNum  = 2 ;
15+  }
1016 for  (List <String > item  : items ) {
11-  if  ((ruleKey .equals ("type" ) && item .get (0 ).equals (ruleValue ))
12-  || (ruleKey .equals ("color" ) && item .get (1 ).equals (ruleValue ))
13-  || (ruleKey .equals ("name" ) && item .get (2 ).equals (ruleValue ))) {
14-  match ++;
17+  if  (item .get (checkRuleNum ).equals (ruleValue )) {
18+  ans ++;
1519 }
1620 }
17-  return  match ;
21+  return  ans ;
1822 }
1923}
                         You can’t perform that action at this time. 
           
                  
0 commit comments