Skip to content

Commit c6ec126

Browse files
committed
update: 添加问题“3289.数字小镇中的捣蛋鬼”的代码和题解 (#1192)
3289: AC.cpp+py+go+java | CE.rust + AC.rust (#1191) cpp - AC,29.70%,35.65% py - AC,100.00%,81.54% go - AC,100.00%,25.81% java - AC,44.37%,5.30% rust - 无语法检查 CE rust - AC,100.00%,45.45% cpp-O(1)空间 - AC,100.00%,74.75% Signed-off-by: LetMeFly666 <[email protected]>
1 parent 50f9ec1 commit c6ec126

17 files changed

+487
-609
lines changed

.commitmsg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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%
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-31 22:19:33
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-31 22:19:51
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
vector<int> getSneakyNumbers(vector<int>& nums) {
14+
unordered_set<int> se;
15+
vector<int> ans;
16+
for (int t : nums) {
17+
if (se.count(t)) {
18+
ans.push_back(t);
19+
} else {
20+
se.insert(t);
21+
}
22+
}
23+
return ans;
24+
}
25+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-31 22:19:33
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-31 22:24:27
6+
*/
7+
package main
8+
9+
func getSneakyNumbers(nums []int) (ans []int) {
10+
se := map[int]struct{}{}
11+
for _, t := range nums {
12+
if _, ok := se[t]; ok {
13+
ans = append(ans, t)
14+
} else {
15+
se[t] = struct{}{}
16+
}
17+
}
18+
return
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-31 22:19:33
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-31 22:27:27
6+
*/
7+
import java.util.Set;
8+
import java.util.HashSet;
9+
10+
class Solution {
11+
public int[] getSneakyNumbers(int[] nums) {
12+
int[] ans = new int[2];
13+
int already = 0;
14+
Set<Integer> se = new HashSet<>();
15+
for (int t : nums) {
16+
if (se.contains(t)) {
17+
ans[already++] = t;
18+
} else {
19+
se.add(t);
20+
}
21+
}
22+
return ans;
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-10-31 22:19:33
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-10-31 22:21:51
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def getSneakyNumbers(self, nums: List[int]) -> List[int]:
11+
se = set()
12+
ans = []
13+
for t in nums:
14+
if t in se:
15+
ans.append(t)
16+
else:
17+
se.add(t)
18+
return ans
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-31 22:19:33
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-31 22:33:07
6+
*/
7+
use std::collections::HashSet;
8+
// THIS IS NOT RIGHT
9+
impl Solution {
10+
pub fn get_sneaky_numbers(nums: Vec<i32>) -> Vec<i32> {
11+
let mut se = HashSet::new();
12+
let mut ans = Vec::with_capacity(2);
13+
for &t in nums {
14+
if se.contains(t) {
15+
ans.push(*t);
16+
} else {
17+
se.inserst(t);
18+
}
19+
}
20+
ans
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-31 22:33:13
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-31 22:39:35
6+
*/
7+
use std::collections::HashSet;
8+
9+
impl Solution {
10+
pub fn get_sneaky_numbers(nums: Vec<i32>) -> Vec<i32> {
11+
let mut se = HashSet::new();
12+
let mut ans = Vec::with_capacity(2);
13+
for t in nums {
14+
if se.contains(&t) {
15+
ans.push(t);
16+
} else {
17+
se.insert(t);
18+
}
19+
}
20+
ans
21+
}
22+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-10-31 22:40:51
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-31 22:49:15
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
vector<int> getSneakyNumbers(vector<int>& nums) {
14+
int xored = 0;
15+
for (int t : nums) {
16+
xored ^= t;
17+
}
18+
for (int i = 0; i < nums.size() - 2; i++) {
19+
xored ^= i;
20+
}
21+
// now xored is x^y
22+
23+
int lowbit = xored & -xored;
24+
int ans1 = 0, ans2 = 0;
25+
26+
for (int t : nums) {
27+
if (t & lowbit) {
28+
ans1 ^= t;
29+
} else {
30+
ans2 ^= t;
31+
}
32+
}
33+
for (int i = 0; i < nums.size() - 2; i++) {
34+
if (i & lowbit) {
35+
ans1 ^= i;
36+
} else {
37+
ans2 ^= i;
38+
}
39+
}
40+
return {ans1, ans2};
41+
}
42+
};

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!("3346-maximum-frequency-of-an-element-after-performing-operations-i.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("3289-the-two-sneaky-numbers-of-digitville.rs"); // 这个fileName是会被脚本替换掉的

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@
10211021
|3272.统计好整数的数目|困难|<a href="https://leetcode.cn/problems/find-the-count-of-good-integers/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/04/12/LeetCode%203272.%E7%BB%9F%E8%AE%A1%E5%A5%BD%E6%95%B4%E6%95%B0%E7%9A%84%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147163366" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-count-of-good-integers/solutions/3648738/letmefly-3272tong-ji-hao-zheng-shu-de-sh-pjy8/" target="_blank">LeetCode题解</a>|
10221022
|3280.将日期转换为二进制表示|简单|<a href="https://leetcode.cn/problems/convert-date-to-binary/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/01/LeetCode%203280.%E5%B0%86%E6%97%A5%E6%9C%9F%E8%BD%AC%E6%8D%A2%E4%B8%BA%E4%BA%8C%E8%BF%9B%E5%88%B6%E8%A1%A8%E7%A4%BA/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144870892" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/convert-date-to-binary/solutions/3036032/letmefly-3280jiang-ri-qi-zhuan-huan-wei-149mv/" target="_blank">LeetCode题解</a>|
10231023
|3285.找到稳定山的下标|简单|<a href="https://leetcode.cn/problems/find-indices-of-stable-mountains/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/12/19/LeetCode%203285.%E6%89%BE%E5%88%B0%E7%A8%B3%E5%AE%9A%E5%B1%B1%E7%9A%84%E4%B8%8B%E6%A0%87/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/144596618" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-indices-of-stable-mountains/solutions/3025068/letmefly-3285zhao-dao-wen-ding-shan-de-x-u3wc/" target="_blank">LeetCode题解</a>|
1024+
|3289.数字小镇中的捣蛋鬼|简单|<a href="https://leetcode.cn/problems/the-two-sneaky-numbers-of-digitville/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/10/31/LeetCode%203289.%E6%95%B0%E5%AD%97%E5%B0%8F%E9%95%87%E4%B8%AD%E7%9A%84%E6%8D%A3%E8%9B%8B%E9%AC%BC/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/154214125" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/the-two-sneaky-numbers-of-digitville/solutions/3820570/letmefly-3289shu-zi-xiao-zhen-zhong-de-d-oz9r/" target="_blank">LeetCode题解</a>|
10241025
|3297.统计重新排列后包含另一个字符串的子字符串数目I|中等|<a href="https://leetcode.cn/problems/count-substrings-that-can-be-rearranged-to-contain-a-string-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/01/09/LeetCode%203297.%E7%BB%9F%E8%AE%A1%E9%87%8D%E6%96%B0%E6%8E%92%E5%88%97%E5%90%8E%E5%8C%85%E5%90%AB%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E5%AD%90%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%95%B0%E7%9B%AEI/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/145031494" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-substrings-that-can-be-rearranged-to-contain-a-string-i/solutions/3042787/letmefly-3297tong-ji-zhong-xin-pai-lie-h-8ele/" target="_blank">LeetCode题解</a>|
10251026
|3305.元音辅音字符串计数I|中等|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/12/LeetCode%203305.%E5%85%83%E9%9F%B3%E8%BE%85%E9%9F%B3%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%AE%A1%E6%95%B0I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146197747" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-i/solutions/3607571/letmefly-3305yuan-yin-fu-yin-zi-fu-chuan-ptkg/" target="_blank">LeetCode题解</a>|
10261027
|3306.元音辅音字符串计数II|中等|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/03/13/LeetCode%203306.%E5%85%83%E9%9F%B3%E8%BE%85%E9%9F%B3%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%AE%A1%E6%95%B0II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/146228751" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/solutions/3609545/letmefly-3306yuan-yin-fu-yin-zi-fu-chuan-7y2q/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)