Public class Num187 duplicate DNA sequence {public List<String> findRepeatedDnaSequences(String s) {List<String> ans = new ArrayList<>(); HashMap<String, Integer> map = new HashMap<>();for (int i = 0; i + 9 < s.length(); i++) {
String substring = s.substring(i, i + 10);
map.put(substring, map.getOrDefault(substring, 0) + 1);
if(map.get(substring)==2) ans.add(substring);
}
returnans; }}Copy the code