We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f4fca92 commit 1dafc9cCopy full SHA for 1dafc9c
src/q/q187.rs
@@ -7,13 +7,14 @@ impl Solution {
7
// 固定得窗口是10,那么移动窗口,每次进来一个字母,又弹出第一个字符,保持10个字符
8
// 每次的10个字符都存储到哈希表中,如果出现重复了,则说明存在重复的序列
9
// AC 8ms 5.3mb 31/31
10
- let mut set = std::collections::HashSet::new();
11
- let mut ans = std::collections::HashSet::new();
12
- s.as_bytes().windows(10).for_each(|arr|
13
- if !set.insert(arr) {
14
- ans.insert(arr);
15
- }
16
- );
17
- ans.iter().map(|arr| arr.iter().map(|&x| x as char).collect()).collect()
+ use std::collections::HashSet;
+ let mut set = HashSet::new();
+ s.as_bytes()
+ .windows(10)
+ .filter(|&arr| !set.insert(arr))
+ .collect::<HashSet<&[u8]>>()
+ .into_iter()
+ .map(|arr| arr.iter().map(|&x| x as char).collect())
18
+ .collect()
19
}
20
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments