-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path392.判断子序列.java
39 lines (34 loc) · 872 Bytes
/
392.判断子序列.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
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* @lc app=leetcode.cn id=392 lang=java
*
* [392] 判断子序列
*/
// @lc code=start
import java.util.Arrays;
class Solution {
public boolean isSubsequence(String s, String t) {
int[][] F = new int[t.length() + 1][26];
Arrays.fill(F[t.length()], t.length());
for (int i = t.length() - 1; i >= 0; i--) {
for (int j = 0; j < 26; j++) {
if (t.charAt(i) == 'a' + j) {
F[i][j] = i;
} else {
F[i][j] = F[i + 1][j];
}
}
}
// process s
int i = 0;
for (char sChar : s.toCharArray()) {
i = F[i][sChar - 'a'];
if (i == t.length()) {
return false;
} else {
i++;
}
}
return true;
}
}
// @lc code=end