当前位置:网站首页>力扣(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;
}
};
边栏推荐
- Cnopendata American Golden Globe Award winning data
- 【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
- Linux server development, MySQL index principle and optimization
- 2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
- 【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
- LeetCode 40:组合总和 II
- The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)
- Linux server development, detailed explanation of redis related commands and their principles
- Padavan manually installs PHP
- [OBS] win capture requires winrt
猜你喜欢

Qt学习27 应用程序中的主窗口

numpy中dot函数使用与解析

Linux server development, SQL statements, indexes, views, stored procedures, triggers

Es FAQ summary

Ansible

追风赶月莫停留,平芜尽处是春山

【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
![[guess-ctf2019] fake compressed packets](/img/a2/7da2a789eb49fa0df256ab565d5f0e.png)
[guess-ctf2019] fake compressed packets
![[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替](/img/e3/cceede6babae3c8a24336c81d98aa7.jpg)
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替

探索Cassandra的去中心化分布式架构
随机推荐
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
Sign up now | oar hacker marathon phase III, waiting for your challenge
快速使用 Jacoco 代码覆盖率统计
C语言二叉树与建堆
What are the positions of communication equipment manufacturers?
Codeforce c.strange test and acwing
【数字IC验证快速入门】11、Verilog TestBench(VTB)入门
leanote私有云笔记搭建
numpy中dot函数使用与解析
【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
Figure out the working principle of gpt3
Pytest+allure+jenkins environment -- completion of pit filling
【webrtc】m98 screen和window采集
Zhilian + AV, AITO asked M7 to do more than ideal one
3D reconstruction - stereo correction
Linux server development, MySQL process control statement
[guess-ctf2019] fake compressed packets
Leetcode 40: combined sum II
PHP exports millions of data
Visualization Document Feb 12 16:42