Skip to content

Commit efb0c41

Browse files
authored
Create Solution.java
1 parent 820bb27 commit efb0c41

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public List<String> findRepeatedDnaSequences(String s) {
3+
Map<String, Integer> map = new HashMap<>();
4+
for (int i = 10; i <= s.length(); ++i) {
5+
String sub = s.substring(i - 10, i);
6+
map.put(sub, map.getOrDefault(sub, 0) + 1);
7+
}
8+
List<String> res = new ArrayList<>();
9+
for (Map.Entry<String, Integer> entry : map.entrySet()) {
10+
if (entry.getValue() > 1) {
11+
res.add(entry.getKey());
12+
}
13+
}
14+
return res;
15+
}
16+
}

0 commit comments

Comments
 (0)