forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1764.java
32 lines (30 loc) · 1015 Bytes
/
_1764.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
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class _1764 {
public static class Solution1 {
public boolean canChoose(int[][] groups, int[] nums) {
int n = groups.length;
List<Integer> numsInt = new ArrayList<>();
for (int num : nums) {
numsInt.add(num);
}
int prevIndex = 0;
for (int i = 0; i < n; i++) {
int[] group = groups[i];
List<Integer> groupInt = new ArrayList<>();
for (int num : group) {
groupInt.add(num);
}
int index = Collections.indexOfSubList(numsInt.subList(prevIndex, numsInt.size()), groupInt);
if (index != -1) {
prevIndex = index + group.length;
} else {
return false;
}
}
return true;
}
}
}