forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_1282.java
29 lines (27 loc) · 961 Bytes
/
_1282.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
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class _1282 {
public static class Solution1 {
public List<List<Integer>> groupThePeople(int[] groupSizes) {
Map<Integer, List<Integer>> map = new HashMap<>();
for (int i = 0; i < groupSizes.length; i++) {
List<Integer> list = map.getOrDefault(groupSizes[i], new ArrayList<>());
list.add(i);
map.put(groupSizes[i], list);
}
List<List<Integer>> result = new ArrayList<>();
for (int key : map.keySet()) {
List<Integer> list = map.get(key);
int i = 0;
do {
result.add(list.subList(i, i + key));
i += key;
} while (i + key <= list.size());
}
return result;
}
}
}