#参数s是待删除字符的原字符串
#参数t是目标字符串
#返回值是一个布尔值,意为能否由s删除一些字符得到t
class Solution:
def canGetString(self, s, t):
pos = 0
for x in t:
while pos < len(s) and s[pos] != x:
pos += 1
if pos == len(s):
return False
pos += 1
return True
if name == ‘main’:
s=“abc”
t=“c”
solution = Solution()
print(" 原string和目标string分别为:", s, t)
print(" 能否实现:", solution.canGetString(s, t))
删除字符串中的字符
最新推荐文章于 2024-06-10 22:18:41 发布