Skip to content

Commit b314490

Browse files
refactor 187
1 parent 02fc3f8 commit b314490

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
lines changed

src/main/java/com/fishercoder/solutions/_187.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020
["AAAAACCCCC", "CCCCCAAAAA"].
2121
*/
2222
public class _187 {
23-
24-
public List<String> findRepeatedDnaSequences(String s) {
25-
Map<String, Integer> map = new HashMap();
26-
for (int i = 0; i < s.length() - 9; i++) {
27-
String sequence = s.substring(i, i + 10);
28-
map.put(sequence, map.getOrDefault(sequence, 0) + 1);
29-
}
30-
List<String> repeatedSequences = new ArrayList<>();
31-
for (Map.Entry<String, Integer> entry : map.entrySet()) {
32-
if (entry.getValue() > 1) {
33-
repeatedSequences.add(entry.getKey());
23+
public static class Solution1 {
24+
public List<String> findRepeatedDnaSequences(String s) {
25+
Map<String, Integer> map = new HashMap();
26+
for (int i = 0; i < s.length() - 9; i++) {
27+
String sequence = s.substring(i, i + 10);
28+
map.put(sequence, map.getOrDefault(sequence, 0) + 1);
3429
}
30+
List<String> repeatedSequences = new ArrayList<>();
31+
for (Map.Entry<String, Integer> entry : map.entrySet()) {
32+
if (entry.getValue() > 1) {
33+
repeatedSequences.add(entry.getKey());
34+
}
35+
}
36+
return repeatedSequences;
3537
}
36-
return repeatedSequences;
3738
}
38-
3939
}

src/test/java/com/fishercoder/_187Test.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,24 @@
1010

1111
import static org.junit.Assert.assertEquals;
1212

13-
/**
14-
* Created by fishercoder on 5/3/17.
15-
*/
1613
public class _187Test {
17-
private static _187 test;
18-
private static String s;
19-
private static List<String> expected;
20-
private static List<String> actual;
14+
private static _187.Solution1 solution1;
15+
private static String s;
16+
private static List<String> expected;
17+
private static List<String> actual;
2118

22-
@BeforeClass
23-
public static void setup() {
24-
test = new _187();
25-
}
19+
@BeforeClass
20+
public static void setup() {
21+
solution1 = new _187.Solution1();
22+
}
2623

27-
@Test
28-
public void test1() {
29-
s = "AAAAAAAAAAA";
30-
System.out.println(s.length());
31-
actual = test.findRepeatedDnaSequences(s);
32-
expected = new ArrayList<>(Arrays.asList("AAAAAAAAAA"));
33-
System.out.println(expected.get(0).length());
34-
assertEquals(expected, actual);
35-
}
24+
@Test
25+
public void test1() {
26+
s = "AAAAAAAAAAA";
27+
System.out.println(s.length());
28+
actual = solution1.findRepeatedDnaSequences(s);
29+
expected = new ArrayList<>(Arrays.asList("AAAAAAAAAA"));
30+
System.out.println(expected.get(0).length());
31+
assertEquals(expected, actual);
32+
}
3633
}

0 commit comments

Comments
 (0)