forked from codemistic/Data-Structures-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode1773.java
More file actions
36 lines (31 loc) · 1012 Bytes
/
Leetcode1773.java
File metadata and controls
36 lines (31 loc) · 1012 Bytes
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
package com.company;
import java.util.ArrayList;
import java.util.List;
public class Leetcode1773 {
public static void main(String[] args) {
List<List<String>> items=new ArrayList<>();
int M = 3;
// for (int i = 0; i < M; i++) {
// items.add(new ArrayList<>());
// }
// items.add({"phone","blue","pixel"});
// items= {{"phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"}};
// String ruleKey = "color", ruleValue = "silver";
}
public static int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
int a=0,c=0;
if(ruleKey.equals("type")){
a=0;
} else if (ruleKey.equals("color")){
a=1;
} else if (ruleKey.equals("name")){
a=2;
}
for (int i = 0; i < items.size(); i++) {
if ((items.get(i)).get(a).equals(ruleValue)){
c++;
}
}
return c;
}
}