Leetcode187. Repeated DNA Sequences重复的DNA序列
所有 DNA 由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:“ACGAATTCCG”。在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助。
编写一个函数来查找 DNA 分子中所有出现超多(过)一次的10个字母长的序列(子串)。
示例:
输入: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT" 输出: ["AAAAACCCCC", "CCCCCAAAAA"]
需要注意长度只能是10位,而且不能有重复。
因为只有4个字母,还有一种方法是使用0,1,2,3代表这四个字母。每个字母占2bit,一个字符串就只需要占20bit。
class Solution
{
public:
vector<string> findRepeatedDnaSequences(string s)
{
int len = s.size();
map<string, int> save;
vector<string> ans;
if (len <= 10)
{
return ans;
}
for (int j = 0; j <= len - 10; j++)
{
string str = string(s.begin() + j, s.begin() + j + 10);
if (save[str] == 1)
{
ans.push_back(str);
save[str]++;
}
else
{
save[str]++;
}
}
return ans;
}
};
Leetcode187. Repeated DNA Sequences重复的DNA序列的更多相关文章
- 187. Repeated DNA Sequences重复的DNA子串序列
[抄题]: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &qu ...
- 187 Repeated DNA Sequences 重复的DNA序列
所有DNA由一系列缩写为A,C,G和 T 的核苷酸组成,例如:“ACGAATTCCG”.在研究DNA时,识别DNA中的重复序列有时非常有用.编写一个函数来查找DNA分子中所有出现超多一次的10个字母长 ...
- [Swift]LeetCode187. 重复的DNA序列 | Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- LeetCode 187. 重复的DNA序列(Repeated DNA Sequences)
187. 重复的DNA序列 187. Repeated DNA Sequences 题目描述 All DNA is composed of a series of nucleotides abbrev ...
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- [LeetCode] 187. Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- leetcode 187. Repeated DNA Sequences 求重复的DNA串 ---------- java
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- leetcode187. 重复的DNA序列
所有 DNA 都由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助.编写一个函数 ...
- [LeetCode] 187. Repeated DNA Sequences 解题思路
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
随机推荐
- php 类静态变量 和 常量消耗内存及时间对比
在对类执行100w次循环后, 常量最快,变量其次,静态变量消耗时间最高 其中: 常量消耗:101.1739毫秒 变量消耗:2039.7689毫秒 静态变量消耗:4084.8911毫秒 测试代码: cl ...
- Core Data could not fulfill a fault
做项目的时候在iOS4系统遇到过这样一个crash,console显示的错误信息是"Core Data could not fulfill a fault". 字面意思是什么?&q ...
- bitset简单用法
bitset的创建: #include<bitset> bitset<32> ar; //默认全为0 bitset<32> ar(n); //n的二进制 bitse ...
- c++ pb_ds库,实现 红黑树,Splay
C++ pb_ds库 #include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/tree_policy.hpp> ...
- idea不断提示=========>This file is indented with tabs instead of 4 spaces
file->other settings ->default settings
- 20140319 const sizeof define 编译时分配内存
1.面试宝典预处理,const,sizeof Define作用定义函数: //用一个宏定义FIND求一个结构体struc里某个变量相对于struc的偏移量,如FIND(student,a)//等于0 ...
- 解决:Map的area属性标签鼠标Hover可以给area加背景
css的area标签是不支持hover的,只有a标签才支持.li标签在IE浏览器下才支持,所以采用jquery的mouseenter和mouseleave事件完成.首先讲jQuery对应的事件:1.m ...
- Servlet接口的抽象方法实现
1.init:初始化方法,在Servlet被创建时执行,只会执行一次2.service:提供服务,每此Servelet被访问时service都会执行3.destroy:销毁方法,在服务器正常关闭时执行 ...
- 关于VSCode的一些常用插件和一些常用设置
常用插件: .Beautify :格式化 html ,js,css .Bracket Pair Colorizer :给括号加上不同的颜色,便于区分不同的区块,使用者可以定义不同括号类型和不同颜色 . ...
- 关于Cadence OrCad 16.6的破解
相信很多人都知道去老吴的博客上找安装包和破解文件,但是上面的自称一键式破解程序.以及破解图文说明,都是很有问题的. 首先,该一键式破解程序默认的文件后缀与该程序指向的安装压缩包后缀不一致:其次,该程序 ...