leetcode 187. Repeated DNA Sequences
2016-03-22 23:45
531 查看
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.
Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.
For example,
这题很直白,直接计数感觉太简单,会超时,于是想了种复杂的方法,提交,失望,超时。索性就试试最直接的方法,就是下面这个
class Solution {
public:
vector<string> findRepeatedDnaSequences(string s) {
vector<string>re;
if (s.size()<11)
return re;
map<string, int>count;
for (int i = 0; i <= s.length() - 10; i++)
{
string str = string(s.begin() + i, s.begin() + i + 10);
count[str]++;
}
for (map<string, int>::iterator it = count.begin(); it != count.end(); it++)
if (it->second > 1)
re.push_back(it->first);
return re;
}
};
靠,竟然通过了。。。彻底无语了
Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.
For example,
Given s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT", Return: ["AAAAACCCCC", "CCCCCAAAAA"].
这题很直白,直接计数感觉太简单,会超时,于是想了种复杂的方法,提交,失望,超时。索性就试试最直接的方法,就是下面这个
class Solution {
public:
vector<string> findRepeatedDnaSequences(string s) {
vector<string>re;
if (s.size()<11)
return re;
map<string, int>count;
for (int i = 0; i <= s.length() - 10; i++)
{
string str = string(s.begin() + i, s.begin() + i + 10);
count[str]++;
}
for (map<string, int>::iterator it = count.begin(); it != count.end(); it++)
if (it->second > 1)
re.push_back(it->first);
return re;
}
};
靠,竟然通过了。。。彻底无语了
相关文章推荐
- 2、贪婪算法例子 parvalue(找零钱)
- Grub Rescue 修复引导
- POJ 1679 The Unique MST (次小生成树)
- UI和View 三种控制方式
- 安装IntelHaxm.exe是出现,This computer meets the requirements for HAXM,....
- 习题 10-23 UVA - 10479 The Hendrie Sequence
- Android——UI和View——控制方式
- windows下安装requests
- js获取checkbox被选中的value值
- leetcode62.[DP] Unique Paths
- Day4.2--Android高级UI控件之AutoCompleteTextView的使用
- 解决 Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
- iOS中UItableView 的重用机制原理
- poj Number Sequence 1019 (打表 &模拟)
- NGUI之UISprite
- 算法 加权quick-union
- codeforces_612C.Replace To Make Regular Bracket Sequence(stack)
- iOS开发-UUID
- leetcode303.[DP] Range Sum Query - Immutable
- Ngui使用粒子