-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert2darrayto3darray.java
More file actions
35 lines (32 loc) · 937 Bytes
/
Copy pathconvert2darrayto3darray.java
File metadata and controls
35 lines (32 loc) · 937 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
import java.util.*;
class Solution {
public List<List<Integer>> findMatrix(int[] nums) {
List<List<Integer>> ans=new ArrayList<>();
HashMap<Integer,Integer> hm=new HashMap<>();
for(int ele:nums){
hm.put(ele,hm.getOrDefault(ele,0)+1);
}
while(!hm.isEmpty())
{
List<Integer> use=new ArrayList<>();
Set<Integer> a = new HashSet<>(hm.keySet());
for(int ele : a)
{
if(hm.containsKey(ele))
{
if(hm.get(ele)>=1)
{
use.add(ele);
hm.put(ele,hm.get(ele)-1);
}
}
if(hm.get(ele)==0)
{
hm.remove(ele);
}
}
ans.add(use);
}
return ans;
}
}