当前位置:网站首页>力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
2022-07-07 04:44:00 【ChaoYue_miku】
DNA序列 由一系列核苷酸组成,缩写为 ‘A’, ‘C’, ‘G’ 和 ‘T’.。
例如,“ACGAATTCCG” 是一个 DNA序列 。
在研究 DNA 时,识别 DNA 中的重复序列非常有用。
给定一个表示 DNA序列 的字符串 s ,返回所有在 DNA 分子中出现不止一次的 长度为 10 的序列(子字符串)。你可以按 任意顺序 返回答案。
示例 1:
输入:s = “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”
输出:[“AAAAACCCCC”,“CCCCCAAAAA”]
示例 2:
输入:s = “AAAAAAAAAAAAA”
输出:[“AAAAAAAAAA”]
提示:
0 <= s.length <= 105
s[i]==‘A’、‘C’、‘G’ or ‘T’
来源:力扣(LeetCode)
方法一:哈希表
C++提交内容:
class Solution {
const int L = 10;
public:
vector<string> findRepeatedDnaSequences(string s) {
vector<string> ans;
unordered_map<string, int> cnt;
int n = s.length();
for (int i = 0; i <= n - L; ++i) {
string sub = s.substr(i, L);
if (++cnt[sub] == 2) {
ans.push_back(sub);
}
}
return ans;
}
};
边栏推荐
- numpy中dot函数使用与解析
- 【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
- Introduction to basic components of wechat applet
- 芯片 設計資料下載
- [quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
- 这5个摸鱼神器太火了!程序员:知道了快删!
- dash plotly
- 【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
- Quickly use Jacobo code coverage statistics
- [webrtc] m98 Screen and Window Collection
猜你喜欢
Most elements
Qt学习26 布局管理综合实例
Thinkcmf6.0 installation tutorial
图解GPT3的工作原理
LeetCode 90:子集 II
Mysql高低版本切换需要修改的配置5-8(此处以aicode为例)
2022焊工(初级)判断题及在线模拟考试
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
Linux server development, SQL statements, indexes, views, stored procedures, triggers
[experience sharing] how to expand the cloud service icon for Visio
随机推荐
[mathematical notes] radian
Rust versus go (which is my preferred language?)
Pytorch parameter initialization
【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
Info | webrtc M97 update
Problem solving: unable to connect to redis
Button wizard script learning - about tmall grabbing red envelopes
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
Force buckle 144 Preorder traversal of binary tree
[matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
Cnopendata list data of Chinese colleges and Universities
[UVM practice] Chapter 2: a simple UVM verification platform (2) only driver verification platform
Redis technology leak detection and filling (II) - expired deletion strategy
贝叶斯定律
2022 tea master (intermediate) examination questions and mock examination
[guess-ctf2019] fake compressed packets
3D reconstruction - stereo correction
[VHDL parallel statement execution]
Use and analysis of dot function in numpy
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)