3217. Delete Nodes From Linked List Present in Array Medium
1/**
2 * [3217] Delete Nodes From Linked List Present in Array
3 *
4 * 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.
5 *
6 * <strong class="example">Example 1:
7 * <div class="example-block">
8 * Input: <span class="example-io">nums = [1,2,3], head = [1,2,3,4,5]</span>
9 * Output: <span class="example-io">[4,5]</span>
10 * Explanation:
11 * <img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample0.png" style="width: 400px; height: 66px;" />
12 * Remove the nodes with values 1, 2, and 3.
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">nums = [1], head = [1,2,1,2,1,2]</span>
17 * Output: <span class="example-io">[2,2,2]</span>
18 * Explanation:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample1.png" style="height: 62px; width: 450px;" />
20 * Remove the nodes with value 1.
21 * </div>
22 * <strong class="example">Example 3:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [5], head = [1,2,3,4]</span>
25 * Output: <span class="example-io">[1,2,3,4]</span>
26 * Explanation:
27 * <img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample2.png" style="width: 400px; height: 83px;" />
28 * No node has value 5.
29 * </div>
30 *
31 * Constraints:
32 *
33 * 1 <= nums.length <= 10^5
34 * 1 <= nums[i] <= 10^5
35 * All elements in nums are unique.
36 * The number of nodes in the given list is in the range [1, 10^5].
37 * 1 <= Node.val <= 10^5
38 * The input is generated such that there is at least one node in the linked list that has a value not present in nums.
39 *
40 */
41pub struct Solution {}
42use crate::util::linked_list::{ListNode, to_list};
43
44// problem: https://leetcode.com/problems/delete-nodes-from-linked-list-present-in-array/
45// discuss: https://leetcode.com/problems/delete-nodes-from-linked-list-present-in-array/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49// Definition for singly-linked list.
50// #[derive(PartialEq, Eq, Clone, Debug)]
51// pub struct ListNode {
52// pub val: i32,
53// pub next: Option<Box<ListNode>>
54// }
55//
56// impl ListNode {
57// #[inline]
58// fn new(val: i32) -> Self {
59// ListNode {
60// next: None,
61// val
62// }
63// }
64// }
65impl Solution {
66 pub fn modified_list(nums: Vec<i32>, head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
67 Some(Box::new(ListNode::new(0)))
68 }
69}
70
71// submission codes end
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn test_3217() {
79 }
80}
81
Back
© 2025 bowen.ge All Rights Reserved.