Skip to content

Practice Delete Nodes From Linked List Present in Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3217
LeetCode Problem

Delete Nodes From Linked List Present in Array

Problem Statement

You are given an array of integers nums and the head of a linked list. Return the head of the modified linked list after removing all nodes from the linked list that have a value that exists in nums.

Source: Delete Nodes From Linked List Present in Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,3], head = [1,2,3,4,5]
Output
[4,5]

# Example 2

Input
nums = [1], head = [1,2,1,2,1,2]
Output
[2,2,2]

# Example 3

Input
nums = [5], head = [1,2,3,4]
Output
[1,2,3,4]

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^5
All elements in nums are unique.
The number of nodes in the given list is in the range [1, 10^5].
1 <= Node.val <= 10^5
The input is generated such that there is at least one node in the linked list that has a value not present in nums.

Related LeetCode Problems

Practice more problems similar to Delete Nodes From Linked List Present in Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.