Skip to content

Commit 6cb976a

Browse files
committed
Time: 44 ms (87.5%), Space: 98.4 MB (12.5%) - LeetHub
1 parent 2e1ce8f commit 6cb976a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val, next) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.next = (next===undefined ? null : next)
6+
* }
7+
*/
8+
/**
9+
* @param {number[]} nums
10+
* @param {ListNode} head
11+
* @return {ListNode}
12+
*/
13+
var modifiedList = function (nums, head) {
14+
const set = new Set(nums);
15+
const dummy = new ListNode(0);
16+
dummy.next = head;
17+
let cur = head;
18+
let prev = dummy;
19+
while (cur) {
20+
if (!set.has(cur.val)) {
21+
prev = cur;
22+
} else {
23+
prev.next = cur.next;
24+
}
25+
cur = cur.next;
26+
}
27+
return dummy.next;
28+
};

0 commit comments

Comments
 (0)