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 ...
随机推荐
- faster-rcnn代码阅读-roi-data层
这一节讲述roi-data层,和这一层有关的结构图如下: roi-data层的prototxt定义如下: layer { name: 'roi-data' type: 'Python' bottom: ...
- LeetCode 746. Min Cost Climbing Stairs (使用最小花费爬楼梯)
题目标签:Dynamic Programming 题目给了我们一组 cost,让我们用最小的cost 走完楼梯,可以从index 0 或者 index 1 出发. 因为每次可以选择走一步,还是走两步, ...
- linux网络速率监控
#!/bin/bash #作者:fafu_li #时间: #监控网卡传输速率 source /etc/profile #加载系统环境变量 source $HOME/.bash_profile #加载用 ...
- [转]mysql主从同步
Mysql镜像机制配置过程主服务器: 192.168.0.25从服务器: 192.168.0.26MYSQL版本:mysql-5.0.22.tar.gz安装日期:2010年5月14日 一.镜 ...
- Putty 两步代理访问互联网
工作在机房,有时需要访问外网. 此时浏览器需要使用代理服务器,访问的流程如下: 由于SERVER2不能直接访问互联网,而SERVER3可以(机房无法直接访问SERVER3)所以需要两步代理. 配置流程 ...
- CodeForces 1152F1 Neko Rules the Catniverse (Small Version)
题目链接:http://codeforces.com/problemset/problem/1152/F1 题目大意 有 n 个星球,给定限制 m,从 x 星球走到 y 星球的条件是,$1 \leq ...
- k8s 映射 外部服务
把外部的服务,通过创建service和endpoint,把它映射到k8s内部来使用. 操作步骤: 在10.0.0.13上安装数据库 yum install mariadb-server -y syst ...
- neo4j常用cypher语句
阅读更多 1.删除带有关系的节点 a.先删除关系 match (n:Node)-[r:关系名称]-() where (n...条件) delete r b.删除节点 match (n:Node ...
- 神经网络 (2)- Alexnet Training on MNIST
文章目录 Win10 Anaconda下配置tensorflow+jupyter notebook环境 AlexNet 识别MNIST Win10 Anaconda下配置tensorflow+jupy ...
- zepto(mark)
Zepto的设计目的是提供 jQuery 的类似的API,但并不是100%覆盖 jQuery .Zepto设计的目的是有一个5-10k的通用库.下载并快速执行.有一个熟悉通用的API,所以你能把你主要 ...