Repeated DNA Sequence

public class repeatedDNASequence {
public List findRepeatedDnaSequences(String s) {
List res=new ArrayList();
if (s.length()<10) return res;
HashMap map=new HashMap();
HashMap dict=new HashMap();
dict.put(‘A’, 0);
dict.put(‘C’, 1); dict.put(‘G’, 2); dict.put(‘T’, 3);
for(int i=0;i<s.length()-9;i++){
String tmp=s.substring(i,i+10);
int temp=0;
for(int j=i;j<i+10;j++){
temp= (temp<<2)| dict.get(s.charAt(j));
}
if (map.containsKey(temp)){
if (map.get(temp)==1){
res.add(convertString(temp));
map.put(temp,-1);
}
}else{
map.put(temp,1);
}
}
return res;

}

public String convertString(int x){
StringBuilder sb=new StringBuilder();
for(int i=0;i>2;
}
return sb.toString();
}
}

Repeated DNA Sequence

Leave a comment