-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJudgeSubSequence0392.java
More file actions
46 lines (38 loc) · 1.18 KB
/
Copy pathJudgeSubSequence0392.java
File metadata and controls
46 lines (38 loc) · 1.18 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* ¶¯Ì¬¹æ»®£ºÅжÏ×ÓÐòÁÐ
*
*/
public class JudgeSubSequence0392{
public static void main(String[] args) {
String s = "abc";
String t = "";
System.out.println(isSubsequence(s, t));
}
public static boolean isSubsequence(String s, String t) {
if (s == null || t == null ) {
return false;
}else if(s.length() == 0) {
return true;
}else if(t.length() == 0){
return false;
}
boolean tab[][] = new boolean[s.length()][t.length()];
for (int i = 0; i <s.length(); i++) {
for (int j = i; j < t.length(); j++) {
if (i==0 && j == 0) {
tab[i][j] = s.charAt(i) == t.charAt(j);
continue;
}else if (i == 0) {
tab[i][j] = s.charAt(i) == t.charAt(j) ? true : tab[i][j-1];
continue;
}
if (s.charAt(i) == t.charAt(j)) {
tab[i][j] = tab[i-1][j-1];
}else {
tab[i][j] = tab[i][j-1];
}
}
}
return tab[s.length()-1][t.length()-1];
}
}