0%

LeetCode-392

题目

结果

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public boolean isSubsequence(String s, String t) {
int p1 = 0, p2 = 0;
while (p1 < s.length() && p2 < t.length()) {
if (s.charAt(p1) == t.charAt(p2)) {
p1++;
p2++;
} else {
p2++;
}
}
return p1 == s.length();
}
}

复杂度

时间复杂度:O(n)

空间复杂度:O(1)