Skip to content

Commit e2e7a19

Browse files
committed
Add solution #3217
1 parent fb56d5f commit e2e7a19

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,7 @@
26832683
3205|[Maximum Array Hopping Score I](./solutions/3205-maximum-array-hopping-score-i.js)|Medium|
26842684
3208|[Alternating Groups II](./solutions/3208-alternating-groups-ii.js)|Medium|
26852685
3215|[Count Triplets with Even XOR Set Bits II](./solutions/3215-count-triplets-with-even-xor-set-bits-ii.js)|Medium|
2686+
3217|[Delete Nodes From Linked List Present in Array](./solutions/3217-delete-nodes-from-linked-list-present-in-array.js)|Medium|
26862687
3221|[Maximum Array Hopping Score II](./solutions/3221-maximum-array-hopping-score-ii.js)|Medium|
26872688
3223|[Minimum Length of String After Operations](./solutions/3223-minimum-length-of-string-after-operations.js)|Medium|
26882689
3227|[Vowels Game in a String](./solutions/3227-vowels-game-in-a-string.js)|Medium|
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* 3217. Delete Nodes From Linked List Present in Array
3+
* https://leetcode.com/problems/delete-nodes-from-linked-list-present-in-array/
4+
* Difficulty: Medium
5+
*
6+
* You are given an array of integers nums and the head of a linked list. Return the head
7+
* of the modified linked list after removing all nodes from the linked list that have
8+
* a value that exists in nums.
9+
*/
10+
11+
/**
12+
* Definition for singly-linked list.
13+
* function ListNode(val, next) {
14+
* this.val = (val===undefined ? 0 : val)
15+
* this.next = (next===undefined ? null : next)
16+
* }
17+
*/
18+
/**
19+
* @param {number[]} nums
20+
* @param {ListNode} head
21+
* @return {ListNode}
22+
*/
23+
var modifiedList = function(nums, head) {
24+
const set = new Set(nums);
25+
const temp = new ListNode(0, head);
26+
let current = temp;
27+
28+
while (current.next) {
29+
if (set.has(current.next.val)) {
30+
current.next = current.next.next;
31+
} else {
32+
current = current.next;
33+
}
34+
}
35+
36+
return temp.next;
37+
};

0 commit comments

Comments
 (0)