-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy path1282.java
More file actions
21 lines (18 loc) · 721 Bytes
/
1282.java
File metadata and controls
21 lines (18 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public List<List<Integer>> groupThePeople(int[] groupSizes) {
Map<Integer, List<Integer>> h = new HashMap<>();
List<List<Integer>> res = new ArrayList<>();
for(int i=0;i<groupSizes.length;i++){
h.putIfAbsent(groupSizes[i], new ArrayList<Integer>());
h.get(groupSizes[i]).add(i);
if(h.get(groupSizes[i]).size() >= groupSizes[i]){
res.add(h.get(groupSizes[i]));
h.put(groupSizes[i], new ArrayList<Integer>());
}
}
// for(Integer k : h.keySet()){
// System.out.println(h.get(k));
// }
return res;
}
}