-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc.java
73 lines (63 loc) · 1.88 KB
/
c.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.*;
public class main {
public static List<String> mixColors(List<List<Integer>> colors, List<List<Integer>> queries) {
// Write your code here
List<String> ans = new ArrayList<String>();
for(int i=0; i < queries.size(); i++)
{
int a = queries.get(i).get(0);
int b = queries.get(i).get(1);
int c = queries.get(i).get(2);
int cA = 0, cB = 0, cC = 0;
for(int j=0; j < colors.size(); j++)
{
if(colors.get(j).get(0) == a)
{
cA = 1;
}
if(colors.get(j).get(1) == b)
{
cB = 1;
}
if(colors.get(j).get(2) == c)
{
cC = 1;
}
}
if(cA == 1 && cB == 1 && cC == 1)
{
ans.add("YES");
}
else
{
ans.add("NO");
}
}
// method 2
List<String> ans = new ArrayList<String>();
Set<Integer> setA = new HashSet<Integer>();
Set<Integer> setB = new HashSet<Integer>();
Set<Integer> setC = new HashSet<Integer>();
for(int i=0; i < colors.size(); i++)
{
setA.add(colors.get(i).get(0));
setB.add(colors.get(i).get(1));
setC.add(colors.get(i).get(2));
}
for(int i=0; i < queries.size(); i++)
{
int a = queries.get(i).get(0);
int b = queries.get(i).get(1);
int c = queries.get(i).get(2);
if(setA.contains(a) && setB.contains(b) && setC.contains(c))
{
ans.add("YES");
}
else
{
ans.add("NO");
}
}
return ans;
}
}