-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCount_Items_Matching_a_Rule_1773.java
More file actions
51 lines (46 loc) · 1.04 KB
/
Count_Items_Matching_a_Rule_1773.java
File metadata and controls
51 lines (46 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package leetcode;
import java.util.ArrayList;
import java.util.List;
class Solution1773 {
public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
int count = 0;
int index;
switch (ruleKey) {
case "type":
index = 0;
break;
case "color":
index = 1;
break;
default:
index = 2;
}
for (List<String> ls : items) {
if (ls.get(index).equals(ruleValue)) {
count++;
}
}
return count;
}
}
public class Count_Items_Matching_a_Rule_1773 {
public static void main(String[] args) {
Solution1773 ns = new Solution1773();
List<List<String>> ls = new ArrayList<>();
ls.add(new ArrayList<>());
ls.add(new ArrayList<>());
ls.add(new ArrayList<>());
ls.get(0).add("phone");
ls.get(0).add("blue");
ls.get(0).add("pixel");
ls.get(1).add("computer");
ls.get(1).add("silver");
ls.get(1).add("lenovo");
ls.get(2).add("phone");
ls.get(2).add("gold");
ls.get(2).add("iphone");
// System.out.println(ls);
int no = ns.countMatches(ls, "color", "silver");
System.out.println(no);
}
}