class Solution {
public List<String> findRepeatedDnaSequences(String s) {
List<String> res = new ArrayList<String>();
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
if (s.length() < 9) {
return res;
}
int key = 0;
for (int i = 0; i < s.length(); i++) {
key = ((key << 3) | (s.charAt(i) & 0x7)) & 0x3fffffff;
if (i < 9) {
continue;
}
if (map.get(key) == null) {
map.put(key, 1);
} else if(map.get(key)==1){
res.add(s.substring(i - 9, i + 1));
map.put(key, 2);
}
}
return res;
}
}
public List<String> findRepeatedDnaSequences(String s) {
List<String> res = new ArrayList<String>();
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
if (s.length() < 9) {
return res;
}
int key = 0;
for (int i = 0; i < s.length(); i++) {
key = ((key << 3) | (s.charAt(i) & 0x7)) & 0x3fffffff;
if (i < 9) {
continue;
}
if (map.get(key) == null) {
map.put(key, 1);
} else if(map.get(key)==1){
res.add(s.substring(i - 9, i + 1));
map.put(key, 2);
}
}
return res;
}
}