Skip to content

Commit f4fca92

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

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/q/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ mod q171;
122122
mod q172;
123123
mod q173;
124124
mod q179;
125+
mod q187;
125126
mod q189;
126127
mod q190;
127128
mod q191;

src/q/q187.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::q::Solution;
2+
3+
#[allow(unused)]
4+
impl Solution {
5+
pub fn find_repeated_dna_sequences(s: String) -> Vec<String> {
6+
// 方法1
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()
18+
}
19+
}

0 commit comments

Comments
 (0)