LeetCode 187. 重复的DNA序列(Repeated DNA Sequences)
187. 重复的DNA序列
187. Repeated DNA Sequences
题目描述
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.
LeetCode187. Repeated DNA Sequences中等
Example:
Output: ["AAAAACCCCC", "CCCCCAAAAA"]
Java 实现
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
class Solution {
public List<String> findRepeatedDnaSequences(String s) {
Set<String> set = new HashSet<>();
Set<String> repeat = new HashSet<>();
for (int i = 0; i + 9 < s.length(); i++) {
String str = s.substring(i, i + 10);
if (!set.add(str)) {
repeat.add(str);
}
}
return new ArrayList<>(repeat);
}
}
参考资料
- https://www.cnblogs.com/grandyang/p/4284205.html
- https://leetcode.com/problems/repeated-dna-sequences/
- https://leetcode-cn.com/problems/repeated-dna-sequences/
LeetCode 187. 重复的DNA序列(Repeated DNA Sequences)的更多相关文章
- [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 ...
- Java实现 LeetCode 187 重复的DNA序列
187. 重复的DNA序列 所有 DNA 都由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对 ...
- Leetcode 187.重复的DNA序列
重复的DNA序列 所有 DNA 由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮 ...
- LeetCode 686. 重复叠加字符串匹配(Repeated String Match)
686. 重复叠加字符串匹配 686. Repeated String Match 题目描述 给定两个字符串 A 和 B,寻找重复叠加字符串 A 的最小次数,使得字符串 B 成为叠加后的字符串 A 的 ...
- LeetCode 459. 重复的子字符串(Repeated Substring Pattern)
459. 重复的子字符串 459. Repeated Substring Pattern 题目描述 给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成.给定的字符串只含有小写英文字母,并且 ...
- DNA序列 (DNA Consensus String,ACM/ICPC Seoul 2006,UVa1368
题目描述:算法竞赛入门经典习题3-7 题目思路:每列出现最多的距离即最短 #include <stdio.h> #include <string.h> int main(int ...
- Q200510-02-02: 重复的DNA序列 SQL解法
重复的DNA序列所有 DNA 都由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:“ACGAATTCCG”.在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助. 编写一个函数来 ...
- Q200510-02: 重复的DNA序列 程序解法
问题: 重复的DNA序列 所有 DNA 都由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:“ACGAATTCCG”.在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助. 编 ...
- [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 ...
随机推荐
- vs下载代码
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u012605477/article/details/62222919Visual Studio 20 ...
- Git学习笔记--实践(三)
文中红色的文字(标为:## 插曲)是在Git学习/实践过程中,我个人遇到的一些问题,每个“## 插曲”之后,都有相应的解决方案. 一.创建版本库 版本库又名仓库,英文名repository,可简单的理 ...
- C++异常处理(二)----声明接口
接口声明的三种形式 抛出一切形式的异常 void freeobj(mycoach &t) { ) { cout <<"精神可嘉~但还是年龄太小" << ...
- Codeforces Round #493 (Div. 2) 【A,B,C】
简单思维题 #include<bits/stdc++.h> using namespace std; #define int long long #define inf 0x3f3f3f3 ...
- 分类模型的性能评价指标(Classification Model Performance Evaluation Metric)
二分类模型的预测结果分为四种情况(正类为1,反类为0): TP(True Positive):预测为正类,且预测正确(真实为1,预测也为1) FP(False Positive):预测为正类,但预测错 ...
- 农场派对(party)(信息学奥赛一本通 1497)
[题目描述] N(1≤N≤1000)头牛要去参加一场在编号为 x(1≤x≤N) 的牛的农场举行的派对.有 M(1≤M≤100000) 条有向道路,每条路长 Ti(1≤Ti≤100):每头牛都必须参加完 ...
- mysql 引擎类型
innodb: 可靠的事物处理引擎,不支持全文搜索 memeory: 数据存储在内存,速度很快 myisam: 性能极高的引擎,支持全文本搜索,但不支持事物
- (二)Cisco dhcp snooping配置解释
#配置dhcp snooping相关命令 Switch(config)#ip dhcp snooping //打开DHCP Snooping功能Switch(config)#ip dhcp snoo ...
- span 不使用float 靠右对齐且垂直居中
一般让div 里的span 靠右对齐用的方法比较多的是float:right. 这次由于各种原因我不想用float 先看效果: HTML 部分 <div class="customer ...
- VS2019(NET Core 3.0)发布单文件可执行程序
NET Core 3.0 发布单文件可执行程序 两种方法. 一.右击vs编辑项目文件,增加PublishSingleFile节点配置,代码如下: <Project Sdk="Micro ...