File tree 2 files changed +41
-43
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder 2 files changed +41
-43
lines changed Original file line number Diff line number Diff line change @@ -25,23 +25,24 @@ A subsequence of a string is a new string which is formed from the original stri
25
25
*/
26
26
public class _392 {
27
27
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 ;
38
43
}
39
44
}
40
- if (j == t .length () && !foundI ) {
41
- return false ;
42
- }
45
+ return true ;
43
46
}
44
- return true ;
45
47
}
46
-
47
48
}
Original file line number Diff line number Diff line change 6
6
7
7
import static junit .framework .Assert .assertEquals ;
8
8
9
- /**
10
- * Created by fishercoder on 5/7/17.
11
- */
12
9
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 ;
18
15
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
+ }
23
20
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
+ }
32
29
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
+ }
41
38
}
You can’t perform that action at this time.
0 commit comments