- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3063.java
24 lines (22 loc) · 778 Bytes
/
_3063.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
packagecom.fishercoder.solutions.fourththousand;
importcom.fishercoder.common.classes.ListNode;
importjava.util.HashMap;
importjava.util.Map;
publicclass_3063 {
publicstaticclassSolution1 {
publicListNodefrequenciesOfElements(ListNodehead) {
Map<Integer, Integer> map = newHashMap<>();
while (head != null) {
map.put(head.val, map.getOrDefault(head.val, 0) + 1);
head = head.next;
}
ListNodepre = newListNode(-1);
ListNodetmp = pre;
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
tmp.next = newListNode(entry.getValue());
tmp = tmp.next;
}
returnpre.next;
}
}
}