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.

For example,

Given s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT",

Return:
["AAAAACCCCC", "CCCCCAAAAA"].
 public class Solution {
public List<String> findRepeatedDnaSequences(String s) {
List<String> list = new ArrayList<String>();
Set<String> temp = new HashSet<String>();
if (s == null || s.length() <= )
return list;
Set<String> set = new HashSet<String>();
for (int i = ; i <= s.length(); i++) {
if (set.contains(s.substring(i - , i))) {
temp.add(s.substring(i - , i));
} else {
set.add(s.substring(i - , i));
}
}
return new ArrayList<String>(temp);
}
}
上一篇:【转】 ubuntu12.04更新源


下一篇:Directx11学习笔记【二十二】 用高度图实现地形