一、题目描述
二、示例
三、难度
简单
四、代码
Java版
class Solution {
public boolean isSubsequence(String s, String t) {
int from = 0;
for (int i = 0; i < s.length(); ++i) {
from = t.indexOf(s.charAt(i), from);
if (from == -1) return false;
++from;
}
return true;
}
}
Python版
class Solution(object):
def isSubsequence(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
from_index = -1
for ch in s:
if t.find(ch, from_index + 1) != -1:
from_index = t.find(ch, from_index + 1)
else:
return False
return True