Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1dafc9c

Browse files
author
ruislan
committed
solved q187
1 parent f4fca92 commit 1dafc9c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

‎src/q/q187.rs‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ impl Solution {
77
// 固定得窗口是10,那么移动窗口,每次进来一个字母,又弹出第一个字符,保持10个字符
88
// 每次的10个字符都存储到哈希表中,如果出现重复了,则说明存在重复的序列
99
// 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()
10+
use std::collections::HashSet;
11+
let mut set = HashSet::new();
12+
s.as_bytes()
13+
.windows(10)
14+
.filter(|&arr| !set.insert(arr))
15+
.collect::<HashSet<&[u8]>>()
16+
.into_iter()
17+
.map(|arr| arr.iter().map(|&x| x as char).collect())
18+
.collect()
1819
}
1920
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /