/*
思路:把所有10位的组合依次存入hashmap 如果重复一次则写入结果 没有的话 写入hashmap
*/
class Solution {
public List<String> findRepeatedDnaSequences(String s) {
List<String> result = new ArrayList<String>();
if(s == null || s.length() == 0) {
return result;
}
HashMap<String, Integer> map = new HashMap<>();
for(int i = 0; i <= s.length() - 10; i++){
String ss = s.substring(i, i + 10);
if(map.containsKey(ss)) {
if(map.get(ss) == 1) {
result.add(ss);
map.put(ss, 2);
}
} else {
map.put(ss, 1);
}
}
return result;
}
}
Repeated DNA Sequences
最新推荐文章于 2019-11-11 21:51:35 发布