当前位置:网站首页>力扣(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;
}
};
边栏推荐
- Leanote private cloud note building
- LeetCode 40:组合总和 II
- CentOS7下安装PostgreSQL11数据库
- [quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)
- Regular e-commerce problems part1
- 2022年茶艺师(中级)考试试题及模拟考试
- [SUCTF 2019]Game
- 2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
- Sign up now | oar hacker marathon phase III, waiting for your challenge
- Figure out the working principle of gpt3
猜你喜欢
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
有 Docker 谁还在自己本地安装 Mysql ?
[unity] several ideas about circular motion of objects
padavan手动安装php
php导出百万数据
Cnopendata American Golden Globe Award winning data
2022焊工(初级)判断题及在线模拟考试
Visualization Document Feb 12 16:42
Shell 脚本的替换功能实现
JS quick start (I)
随机推荐
[unity] several ideas about circular motion of objects
2022制冷与空调设备运行操作复训题库及答案
PHP exports millions of data
解决问题:Unable to connect to Redis
Force buckle 144 Preorder traversal of binary tree
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
Thinkcmf6.0 installation tutorial
[VHDL parallel statement execution]
Padavan manually installs PHP
Quickly use Jacobo code coverage statistics
Implementation of replacement function of shell script
Linux server development, MySQL cache strategy
C语言队列
Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
[Stanford Jiwang cs144 project] lab4: tcpconnection
[matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
Yugu p1020 missile interception (binary search)
【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
图解GPT3的工作原理
Linux server development, SQL statements, indexes, views, stored procedures, triggers