File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ mod q171;
122122mod q172;
123123mod q173;
124124mod q179;
125+ mod q187;
125126mod q189;
126127mod q190;
127128mod q191;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments