Skip to content

Commit 264bc09

Browse files
committed
update: 添加问题“3217.从链表中移除在数组中存在的节点”的代码和题解 (#1194)
3217: (CE+WA).cpp + AC.cpp (#1193) Signed-off-by: LetMeFly666 <[email protected]>
1 parent c6ec126 commit 264bc09

15 files changed

+275
-39
lines changed

.commitmsg

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
3289: AC.cpp+py+go+java | CE.rust + AC.rust (#1191)
2-
3-
cpp - AC,29.70%,35.65%
4-
py - AC,100.00%,81.54%
5-
go - AC,100.00%,25.81%
6-
java - AC,44.37%,5.30%
7-
rust - 无语法检查 CE
8-
rust - AC,100.00%,45.45%
9-
cpp-O(1)空间 - AC,100.00%,74.75%
1+
3217: (CE+WA).cpp + AC.cpp (#1193)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-11-01 21:45:28
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-11-01 21:54:03
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
// THIS IS NOT RIGHT
11+
/**
12+
* Definition for singly-linked list.
13+
* struct ListNode {
14+
* int val;
15+
* ListNode *next;
16+
* ListNode() : val(0), next(nullptr) {}
17+
* ListNode(int x) : val(x), next(nullptr) {}
18+
* ListNode(int x, ListNode *next) : val(x), next(next) {}
19+
* };
20+
*/
21+
class Solution {
22+
public:
23+
ListNode* modifiedList(vector<int>& nums, ListNode* now) {
24+
unordered_set<int> se;
25+
ListNode* head(0, now);
26+
ListNode* last = head;
27+
while (now) {
28+
if (se.count(now->val)) {
29+
now = now->next;
30+
last->next = now;
31+
} else {
32+
last = now;
33+
now = now->next;
34+
}
35+
}
36+
return head->next;
37+
}
38+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
/**
4+
* Definition for singly-linked list.
5+
* type ListNode struct {
6+
* Val int
7+
* Next *ListNode
8+
* }
9+
*/
10+
func modifiedList(nums []int, head *ListNode) *ListNode {
11+
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode() {}
7+
* ListNode(int val) { this.val = val; }
8+
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9+
* }
10+
*/
11+
class Solution {
12+
public ListNode modifiedList(int[] nums, ListNode head) {
13+
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List
2+
3+
# Definition for singly-linked list.
4+
# class ListNode:
5+
# def __init__(self, val=0, next=None):
6+
# self.val = val
7+
# self.next = next
8+
class Solution:
9+
def modifiedList(self, nums: List[int], head: Optional[ListNode]) -> Optional[ListNode]:
10+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Definition for singly-linked list.
2+
// #[derive(PartialEq, Eq, Clone, Debug)]
3+
// pub struct ListNode {
4+
// pub val: i32,
5+
// pub next: Option<Box<ListNode>>
6+
// }
7+
//
8+
// impl ListNode {
9+
// #[inline]
10+
// fn new(val: i32) -> Self {
11+
// ListNode {
12+
// next: None,
13+
// val
14+
// }
15+
// }
16+
// }
17+
impl Solution {
18+
pub fn modified_list(nums: Vec<i32>, head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
19+
20+
}
21+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-11-01 21:53:51
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-11-01 21:54:45
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
/**
12+
* Definition for singly-linked list.
13+
* struct ListNode {
14+
* int val;
15+
* ListNode *next;
16+
* ListNode() : val(0), next(nullptr) {}
17+
* ListNode(int x) : val(x), next(nullptr) {}
18+
* ListNode(int x, ListNode *next) : val(x), next(next) {}
19+
* };
20+
*/
21+
class Solution {
22+
public:
23+
ListNode* modifiedList(vector<int>& nums, ListNode* now) {
24+
unordered_set<int> se(nums.begin(), nums.end());
25+
ListNode* head = new ListNode(0, now);
26+
ListNode* last = head;
27+
while (now) {
28+
if (se.count(now->val)) {
29+
now = now->next;
30+
last->next = now;
31+
} else {
32+
last = now;
33+
now = now->next;
34+
}
35+
}
36+
return head->next;
37+
}
38+
};

Codes/3289-the-two-sneaky-numbers-of-digitville.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/*
22
* @Author: LetMeFly
3-
* @Date: 2025-10-31 22:19:33
3+
* @Date: 2025-10-31 22:33:13
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2025-10-31 22:33:07
5+
* @LastEditTime: 2025-10-31 22:39:35
66
*/
77
use std::collections::HashSet;
8-
// THIS IS NOT RIGHT
8+
99
impl Solution {
1010
pub fn get_sneaky_numbers(nums: Vec<i32>) -> Vec<i32> {
1111
let mut se = HashSet::new();
1212
let mut ans = Vec::with_capacity(2);
13-
for &t in nums {
14-
if se.contains(t) {
15-
ans.push(*t);
13+
for t in nums {
14+
if se.contains(&t) {
15+
ans.push(t);
1616
} else {
17-
se.inserst(t);
17+
se.insert(t);
1818
}
1919
}
2020
ans

Codes/3289-the-two-sneaky-numbers-of-digitville_Right.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-10-30 22:44:18
66
*/
77
pub struct Solution;
8-
include!("3289-the-two-sneaky-numbers-of-digitville.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("3217-delete-nodes-from-linked-list-present-in-array.rs"); // 这个fileName是会被脚本替换掉的

0 commit comments

Comments
 (0)