class Solution {
HashMap<String, Integer> hm;
HashSet ls;
public List<String> findRepeatedDnaSequences(String s) {
hm = new HashMap<String, Integer>();
ls = new HashSet<String>();
for (int i = 0; i < s.length(); i++) { // i + 10 <= s.length() 改进
int j = i + 10; //降低复杂度
if (j <= s.length()) {
if (hm.containsKey(String.valueOf(s.substring(i, j)))&&hm.get(String.valueOf(s.substring(i, j)))!=2) {
ls.add(String.valueOf(s.substring(i, j))); //这里我也不知道为什么会出现重复 导致我用哈希表
hm.replace(String.valueOf(s.substring(i, j)), 2);
} else
hm.put(String.valueOf(s.substring(i, j)), 1);
}
}
return new ArrayList(ls);
}
}