Skip to content

Commit 9ea3662

Browse files
refactor 392
1 parent f7d398a commit 9ea3662

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,24 @@ A subsequence of a string is a new string which is formed from the original stri
2525
*/
2626
public class _392 {
2727

28-
public boolean isSubsequence(String s, String t) {
29-
int left = 0;
30-
for (int i = 0; i < s.length(); i++) {
31-
boolean foundI = false;
32-
int j = left;
33-
for (; j < t.length(); j++) {
34-
if (s.charAt(i) == t.charAt(j)) {
35-
left = j + 1;
36-
foundI = true;
37-
break;
28+
public static class Solution1 {
29+
public boolean isSubsequence(String s, String t) {
30+
int left = 0;
31+
for (int i = 0; i < s.length(); i++) {
32+
boolean foundI = false;
33+
int j = left;
34+
for (; j < t.length(); j++) {
35+
if (s.charAt(i) == t.charAt(j)) {
36+
left = j + 1;
37+
foundI = true;
38+
break;
39+
}
40+
}
41+
if (j == t.length() && !foundI) {
42+
return false;
3843
}
3944
}
40-
if (j == t.length() && !foundI) {
41-
return false;
42-
}
45+
return true;
4346
}
44-
return true;
4547
}
46-
4748
}

src/test/java/com/fishercoder/_392Test.java

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,33 @@
66

77
import static junit.framework.Assert.assertEquals;
88

9-
/**
10-
* Created by fishercoder on 5/7/17.
11-
*/
129
public class _392Test {
13-
private static _392 test;
14-
private static String s;
15-
private static String t;
16-
private static boolean expected;
17-
private static boolean actual;
10+
private static _392.Solution1 solution1;
11+
private static String s;
12+
private static String t;
13+
private static boolean expected;
14+
private static boolean actual;
1815

19-
@BeforeClass
20-
public static void setup() {
21-
test = new _392();
22-
}
16+
@BeforeClass
17+
public static void setup() {
18+
solution1 = new _392.Solution1();
19+
}
2320

24-
@Test
25-
public void test1() {
26-
s = "abc";
27-
t = "ahbgdc";
28-
expected = true;
29-
actual = test.isSubsequence(s, t);
30-
assertEquals(expected, actual);
31-
}
21+
@Test
22+
public void test1() {
23+
s = "abc";
24+
t = "ahbgdc";
25+
expected = true;
26+
actual = solution1.isSubsequence(s, t);
27+
assertEquals(expected, actual);
28+
}
3229

33-
@Test
34-
public void test2() {
35-
s = "axc";
36-
t = "ahbgdc";
37-
expected = false;
38-
actual = test.isSubsequence(s, t);
39-
assertEquals(expected, actual);
40-
}
30+
@Test
31+
public void test2() {
32+
s = "axc";
33+
t = "ahbgdc";
34+
expected = false;
35+
actual = solution1.isSubsequence(s, t);
36+
assertEquals(expected, actual);
37+
}
4138
}

0 commit comments

Comments
 (0)