|
| 1 | +<h2><a href="https://leetcode.com/problems/delete-nodes-from-linked-list-present-in-array">3501. Delete Nodes From Linked List Present in Array</a></h2><h3>Medium</h3><hr><p>You are given an array of integers <code>nums</code> and the <code>head</code> of a linked list. Return the <code>head</code> of the modified linked list after <strong>removing</strong> all nodes from the linked list that have a value that exists in <code>nums</code>.</p> |
| 2 | + |
| 3 | +<p> </p> |
| 4 | +<p><strong class="example">Example 1:</strong></p> |
| 5 | + |
| 6 | +<div class="example-block"> |
| 7 | +<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3], head = [1,2,3,4,5]</span></p> |
| 8 | + |
| 9 | +<p><strong>Output:</strong> <span class="example-io">[4,5]</span></p> |
| 10 | + |
| 11 | +<p><strong>Explanation:</strong></p> |
| 12 | + |
| 13 | +<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample0.png" style="width: 400px; height: 66px;" /></strong></p> |
| 14 | + |
| 15 | +<p>Remove the nodes with values 1, 2, and 3.</p> |
| 16 | +</div> |
| 17 | + |
| 18 | +<p><strong class="example">Example 2:</strong></p> |
| 19 | + |
| 20 | +<div class="example-block"> |
| 21 | +<p><strong>Input:</strong> <span class="example-io">nums = [1], head = [1,2,1,2,1,2]</span></p> |
| 22 | + |
| 23 | +<p><strong>Output:</strong> <span class="example-io">[2,2,2]</span></p> |
| 24 | + |
| 25 | +<p><strong>Explanation:</strong></p> |
| 26 | + |
| 27 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample1.png" style="height: 62px; width: 450px;" /></p> |
| 28 | + |
| 29 | +<p>Remove the nodes with value 1.</p> |
| 30 | +</div> |
| 31 | + |
| 32 | +<p><strong class="example">Example 3:</strong></p> |
| 33 | + |
| 34 | +<div class="example-block"> |
| 35 | +<p><strong>Input:</strong> <span class="example-io">nums = [5], head = [1,2,3,4]</span></p> |
| 36 | + |
| 37 | +<p><strong>Output:</strong> <span class="example-io">[1,2,3,4]</span></p> |
| 38 | + |
| 39 | +<p><strong>Explanation:</strong></p> |
| 40 | + |
| 41 | +<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample2.png" style="width: 400px; height: 83px;" /></strong></p> |
| 42 | + |
| 43 | +<p>No node has value 5.</p> |
| 44 | +</div> |
| 45 | + |
| 46 | +<p> </p> |
| 47 | +<p><strong>Constraints:</strong></p> |
| 48 | + |
| 49 | +<ul> |
| 50 | + <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> |
| 51 | + <li><code>1 <= nums[i] <= 10<sup>5</sup></code></li> |
| 52 | + <li>All elements in <code>nums</code> are unique.</li> |
| 53 | + <li>The number of nodes in the given list is in the range <code>[1, 10<sup>5</sup>]</code>.</li> |
| 54 | + <li><code>1 <= Node.val <= 10<sup>5</sup></code></li> |
| 55 | + <li>The input is generated such that there is at least one node in the linked list that has a value not present in <code>nums</code>.</li> |
| 56 | +</ul> |
0 commit comments