当前位置:网站首页>187. Repeated DNA sequence
187. Repeated DNA sequence
2022-07-26 08:55:00 【apprentice.】
subject :
Answer key :
It is stated in the question that the length is 10. Therefore, the idea of sliding window can be used to solve this problem .
First, you can maintain a length of 10 The window of is used to intercept strings , Then for the string in the window , It is necessary to judge whether there has been , If it only appears before, add it to the result list , Cycle through the window , Finally, the result list can be de duplicated .
For the above mentioned , How to judge whether a string has appeared , have access to map Data structure , Each occurrence corresponds to the string key Of value value +1
If you use Java To write this question , You can use set Data structure of , Initialize two set, Move the window once at a time , Judge whether the intercepted string is in the first set in , If in the first set in , Then add it to the second set. Otherwise, only add it to the first set. because set The data structure of can help us to de duplicate . and Go Language doesn't have set Such a data structure , So we used map To replace
Here are Go The language code
func findRepeatedDnaSequences(s string) []string {
L := 10
seen := make(map[string]int)
ret := make([]string, 0)
for start := 0; start+L-1 < len(s); start++ {
curStr := s[start : start+L]
if seen[curStr] == 1 {
ret = append(ret, curStr)
}
seen[curStr]++
}
return ret
}
边栏推荐
- Store a group of positive and negative numbers respectively, and count the number of 0 -- assembly language implementation
- [freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls
- 海内外媒体宣发自媒体发稿要严格把握内容关
- Pxe原理和概念
- The idea shortcut key ALT realizes the whole column operation
- Introduction to AWD attack and defense competition
- Oracle 19C OCP 1z0-083 question bank (7-12)
- 【搜索专题】看完必会的搜索问题之洪水覆盖
- Deploy prometheus+grafana monitoring platform
- Espressif 玩转 编译环境
猜你喜欢
Foundry教程:使用多种方式编写可升级的智能合约(上)
Memory management - dynamic partition allocation simulation
PXE principles and concepts
ES6 modular import and export) (realize page nesting)
Transfer guide printing system based on C language design
KV database based on raft consensus protocol
Database operation skills 7
Registration of finite element learning knowledge points
【LeetCode数据库1050】合作过至少三次的演员和导演(简单题)
SSH,NFS,FTP
随机推荐
day06 作业--技能题6
Foundry tutorial: writing scalable smart contracts in various ways (Part 1)
day06 作业---技能题7
2022年收益率最高的理财产品是哪个?
[suggestions collection] summary of MySQL 30000 word essence - locking mechanism and performance tuning (IV) [suggestions collection]
[recommended collection] MySQL 30000 word essence summary index (II) [easy to understand]
Arbitrum launched the anytrust chain to meet the diverse needs of ecological projects
第6天总结&数据库作业
[search topics] flood coverage of search questions after reading the inevitable meeting
Espressif plays with the compilation environment
Store a group of positive and negative numbers respectively, and count the number of 0 -- assembly language implementation
合工大苍穹战队视觉组培训Day5——机器学习,图像识别项目
Oracle 19C OCP 1z0-082 certification examination question bank (36-41)
【LeetCode数据库1050】合作过至少三次的演员和导演(简单题)
Which of count (*), count (primary key ID), count (field) and count (1) in MySQL is more efficient? "Suggested collection"
Study notes of automatic control principle --- stability analysis of control system
MySQL 8.0 OCP 1z0-908 certification examination question bank 1
数据库操作 题目一
My meeting of OA project (query)
Xshell batch send command to multiple sessions