forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_187.java
25 lines (23 loc) · 833 Bytes
/
_187.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class _187 {
public static class Solution1 {
public List<String> findRepeatedDnaSequences(String s) {
Map<String, Integer> map = new HashMap();
for (int i = 0; i < s.length() - 9; i++) {
String sequence = s.substring(i, i + 10);
map.put(sequence, map.getOrDefault(sequence, 0) + 1);
}
List<String> repeatedSequences = new ArrayList<>();
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() > 1) {
repeatedSequences.add(entry.getKey());
}
}
return repeatedSequences;
}
}
}