public List<String> findRepeatedDnaSequences(String s){ Set<String> res = new HashSet<>(); HashSet<String> set = new HashSet<>(); for (int i = 0; i <= s.length() - 10; i++) { String temp = s.substring(i, i + 10); if (set.contains(temp)) { res.add(temp); } else { set.add(temp); } } returnnew ArrayList<>(res); }