当前位置:网站首页>Leetcode 187 Repeated DNA sequence (2022.07.06)
Leetcode 187 Repeated DNA sequence (2022.07.06)
2022-07-07 08:10:00 【ChaoYue_ miku】
DNA Sequence It consists of a series of nucleotides , Abbreviation for ‘A’, ‘C’, ‘G’ and ‘T’..
for example ,“ACGAATTCCG” It's a DNA Sequence .
Research on DNA when , distinguish DNA The repeats in are very useful .
Given a representation DNA Sequence String s , Return all in DNA More than once in a molecule The length is 10 Sequence ( Substring ). You can press In any order Return to the answer .
Example 1:
Input :s = “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”
Output :[“AAAAACCCCC”,“CCCCCAAAAA”]
Example 2:
Input :s = “AAAAAAAAAAAAA”
Output :[“AAAAAAAAAA”]
Tips :
0 <= s.length <= 105
s[i]==‘A’、‘C’、‘G’ or ‘T’
source : Power button (LeetCode)
Method 1 : Hashtable
C++ Submission :
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;
}
};
边栏推荐
- The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
- LeetCode简单题之判断一个数的数字计数是否等于数位的值
- 复杂网络建模(一)
- Paddlepaddle 29 dynamically modify the network structure without model definition code (relu changes to prelu, conv2d changes to conv3d, 2D semantic segmentation model changes to 3D semantic segmentat
- Example of file segmentation
- 【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
- game攻防世界逆向
- Real time monitoring of dog walking and rope pulling AI recognition helps smart city
- C language queue
- Recursive method to verify whether a tree is a binary search tree (BST)
猜你喜欢
Fast parsing intranet penetration escorts the document encryption industry
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
LeetCode简单题之判断一个数的数字计数是否等于数位的值
2022 National latest fire-fighting facility operator (primary fire-fighting facility operator) simulation questions and answers
Interactive book delivery - signed version of Oracle DBA work notes
Linux server development, MySQL index principle and optimization
Linux server development, MySQL transaction principle analysis
互动送书-《Oracle DBA工作笔记》签名版
Dedecms collects content without writing rules
[matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
随机推荐
Thinkcmf6.0安装教程
LeetCode简单题之字符串中最大的 3 位相同数字
Linux server development, redis protocol and asynchronous mode
快解析内网穿透为文档加密行业保驾护航
ZCMU--1492: Problem D(C语言)
LeetCode简单题之判断一个数的数字计数是否等于数位的值
Search for an element in a binary search tree (BST)
QT learning 26 integrated example of layout management
[quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)
Call pytorch API to complete linear regression
JS quick start (I)
Interactive book delivery - signed version of Oracle DBA work notes
Paddlepaddle 29 dynamically modify the network structure without model definition code (relu changes to prelu, conv2d changes to conv3d, 2D semantic segmentation model changes to 3D semantic segmentat
Explore dry goods! Apifox construction ideas
复杂网络建模(二)
The element with setfieldsvalue set is obtained as undefined with GetFieldValue
[step on the pit series] H5 cross domain problem of uniapp
Rust versus go (which is my preferred language?)
Myabtis_Plus
Recursive method to construct binary tree from preorder and inorder traversal sequence