- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1836.java
28 lines (26 loc) · 862 Bytes
/
_1836.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
packagecom.fishercoder.solutions.secondthousand;
importcom.fishercoder.common.classes.ListNode;
importjava.util.HashMap;
importjava.util.Map;
publicclass_1836 {
publicstaticclassSolution1 {
publicListNodedeleteDuplicatesUnsorted(ListNodehead) {
Map<Integer, Integer> map = newHashMap<>();
ListNodetmp = head;
while (tmp != null) {
map.put(tmp.val, map.getOrDefault(tmp.val, 0) + 1);
tmp = tmp.next;
}
ListNodepre = newListNode(-1);
tmp = pre;
while (head != null) {
if (map.get(head.val) == 1) {
tmp.next = newListNode(head.val);
tmp = tmp.next;
}
head = head.next;
}
returnpre.next;
}
}
}