字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abcde"的一个子序列,而"aec"不是)。
【示例 1】
输入:s = "abc", t = "ahbgdc"
输出:true
【示例 2】
输入:s = "axc", t = "ahbgdc"
输出:false
字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abcde"的一个子序列,而"aec"不是)。
【示例 1】
输入:s = "abc", t = "ahbgdc"
输出:true
【示例 2】
输入:s = "axc", t = "ahbgdc"
输出:false
这样?
def contains(s,t):
preIndex=0
for c in s:
index=t.find(c,preIndex)
if index==-1 or preIndex>index:
return False
else:
preIndex=index+1#从下个字符找
return True
s=input("请输入s的值")
t=input("请输入t的值")
print(contains(s,t))