File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 268326833205|[ Maximum Array Hopping Score I] ( ./solutions/3205-maximum-array-hopping-score-i.js ) |Medium|
268426843208|[ Alternating Groups II] ( ./solutions/3208-alternating-groups-ii.js ) |Medium|
268526853215|[ 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|
268626873221|[ Maximum Array Hopping Score II] ( ./solutions/3221-maximum-array-hopping-score-ii.js ) |Medium|
268726883223|[ Minimum Length of String After Operations] ( ./solutions/3223-minimum-length-of-string-after-operations.js ) |Medium|
268826893227|[ Vowels Game in a String] ( ./solutions/3227-vowels-game-in-a-string.js ) |Medium|
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments