# Middle-题目96：187. Repeated DNA Sequences

49人阅读 评论(0)

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,
Given s = “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”,
Return:
[“AAAAACCCCC”, “CCCCCAAAAA”].

public class Solution {
public List<String> findRepeatedDnaSequences(String s) {
List<String> list = new ArrayList<String>();
HashMap<String, Integer> dict = new HashMap<String, Integer>();
for(int i = 0;i<=s.length()-10;i++) {
String substr = s.substring(i,i+10);
if(!dict.containsKey(substr)) {
dict.put(substr, 1);
}
else {
int value = dict.get(substr) + 1;
if(value>2)
continue;
dict.put(substr, value);
if(value == 2)
}
}
return list;
}
}

public class Solution {
public List<String> findRepeatedDnaSequences(String DNA) {
ArrayList<String> res = new ArrayList<String>();
if(DNA.length()<10)    return res;
HashSet<Integer> once = new HashSet<Integer>();
HashSet<Integer> twice = new HashSet<Integer>();
int[] map = new int[26];
map['A'-'A'] = 0;
map['C'-'A'] = 1;
map['G'-'A'] = 2;
map['T'-'A'] = 3;
int enc = 0;
for(int i=0; i<9; ++i){
enc <<=2;
enc |= map[DNA.charAt(i)-'A'];
}
for(int j=9; j<DNA.length(); ++j){
enc <<=2;
enc &= 0xfffff;
enc |= map[DNA.charAt(j)-'A'];
}
return res;
}
}

cmershen的碎碎念：

0
0

【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐（算法+实战）--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：55301次
• 积分：3192
• 等级：
• 排名：第10658名
• 原创：270篇
• 转载：53篇
• 译文：0篇
• 评论：7条
文章分类
最新评论