- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3217.java
37 lines (35 loc) · 1.1 KB
/
_3217.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
30
31
32
33
34
35
36
37
packagecom.fishercoder.solutions.fourththousand;
importcom.fishercoder.common.classes.ListNode;
importjava.util.ArrayList;
importjava.util.HashSet;
importjava.util.List;
importjava.util.Set;
publicclass_3217 {
publicstaticclassSolution1 {
publicListNodemodifiedList(int[] nums, ListNodehead) {
Set<Integer> set = newHashSet<>();
for (intnum : nums) {
set.add(num);
}
ListNodetmp = head;
List<Integer> list = newArrayList<>();
while (tmp != null) {
if (!set.contains(tmp.val)) {
list.add(tmp.val);
}
tmp = tmp.next;
}
if (list.size() == 0) {
returnnull;
}
ListNodepre = newListNode(-1);
ListNodetmp2 = newListNode(list.get(0));
pre.next = tmp2;
for (inti = 1; i < list.size(); i++) {
tmp2.next = newListNode(list.get(i));
tmp2 = tmp2.next;
}
returnpre.next;
}
}
}