当前位置:网站首页>力扣(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;
}
};
边栏推荐
- Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
- Thinkcmf6.0 installation tutorial
- 2022 welder (elementary) judgment questions and online simulation examination
- C语言队列
- php导出百万数据
- 这5个摸鱼神器太火了!程序员:知道了快删!
- [Stanford Jiwang cs144 project] lab3: tcpsender
- 【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
- You Li takes you to talk about C language 6 (common keywords)
- Button wizard script learning - about tmall grabbing red envelopes
猜你喜欢
Wechat applet data binding multiple data
【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
QT learning 26 integrated example of layout management
Implementation of replacement function of shell script
Codeforces Global Round 19
Leetcode 90: subset II
Why should we understand the trend of spot gold?
Custom class loader loads network class
QT learning 28 toolbar in the main window
LeetCode 40:组合总和 II
随机推荐
[UVM practice] Chapter 2: a simple UVM verification platform (2) only driver verification platform
Implementation of replacement function of shell script
【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
Pytest+allure+jenkins environment -- completion of pit filling
PHP exports millions of data
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
Common method signatures and meanings of Iterable, collection and list
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
Custom class loader loads network class
太真实了,原来自己一直没有富裕起来是有原因的
B. Value sequence thinking
【VHDL 并行语句执行】
padavan手动安装php
Explore Cassandra's decentralized distributed architecture
【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
Chip design data download
Thinkcmf6.0 installation tutorial
buuctf misc USB
2022焊工(初级)判断题及在线模拟考试
leanote私有云笔记搭建