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 ...
随机推荐
- faster-rcnn系列原理介绍及概念讲解
faster-rcnn系列原理介绍及概念讲解 faster-rcnn系列原理介绍及概念讲解2 转:作者:马塔 链接:https://www.zhihu.com/question/42205480/an ...
- LeetCode 881. Boats to Save People
原题链接在这里:https://leetcode.com/problems/boats-to-save-people/ 题目: The i-th person has weight people[i] ...
- element ui,input框输入时enter健进行搜索
<el-form-item label="企业名称"> <el-input v-model="formSearch.kw" @keyup.en ...
- 前后端通信—CORS(支持跨域)
根据前端跨域的那些事这篇文章中的跨域的理解这一块,我们重新创建两个服务,第一个服务使用了test.html const http = require('http') const fs = requir ...
- spring boot读取Excel
首先引入相关依赖 <!--解析office相关文件--> <dependency> <groupId>org.apache.poi</groupId> ...
- ICEM-三角形特征几何
原视频下载地址:https://pan.baidu.com/s/1qY8SKri 密码: wf17
- Hadoop(五)—— HDFS NameNode、DataNode工作机制
一.NN与2NN工作机制 NameNode(NN) 1.当HDFS启动时,会加载日志(edits)和镜像文件(fsImage)到内存中. 2-4.当元数据的增删改查请求进来时,NameNode会先将操 ...
- [C++] new和delete运算符使用方法
new 和 delete 是C++语言中的两个运算符,配套使用. new:用于分配内存,与C语言中的 malloc 相同,分配在堆内存 delete:用于释放内存,与C语言中的 free 相同,释放堆 ...
- python opencv PyQt5
import cv2 import numpy as np import sys from PyQt5.QtGui import * from PyQt5.QtCore import * from P ...
- @MatrixVariable的使用
@MatrixVariable的使用 博客分类: J2EE 在Spring3.2 后,一个@MatrixVariable出现了,这个注解的出现拓展了URL请求地址的功能. Matrix Varia ...