当前位置:网站首页>力扣(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;
}
};
边栏推荐
- 探索干货篇!Apifox 建设思路
- Qt学习27 应用程序中的主窗口
- Rust Versus Go(哪种是我的首选语言?)
- 【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
- [webrtc] m98 Screen and Window Collection
- Linux server development, MySQL index principle and optimization
- Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
- C language queue
- Main window in QT learning 27 application
- 2022年茶艺师(中级)考试试题及模拟考试
猜你喜欢
央视太暖心了,手把手教你写HR最喜欢的简历
padavan手动安装php
You Li takes you to talk about C language 6 (common keywords)
Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
探索Cassandra的去中心化分布式架构
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
Wechat applet data binding multiple data
Technology cloud report: from robot to Cobot, human-computer integration is creating an era
SQL优化的魅力!从 30248s 到 0.001s
随机推荐
Implementation of replacement function of shell script
Linux server development, MySQL cache strategy
Installing postgresql11 database under centos7
Figure out the working principle of gpt3
Explore Cassandra's decentralized distributed architecture
[experience sharing] how to expand the cloud service icon for Visio
Rust Versus Go(哪种是我的首选语言?)
2022制冷与空调设备运行操作复训题库及答案
Chip design data download
Leanote private cloud note building
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
Linux server development, detailed explanation of redis related commands and their principles
[OBS] win capture requires winrt
[quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)
QT learning 26 integrated example of layout management
Content of string
2022 National latest fire-fighting facility operator (primary fire-fighting facility operator) simulation questions and answers
Qt学习27 应用程序中的主窗口
MySQL multi column index (composite index) features and usage scenarios
Linux server development, MySQL transaction principle analysis