Python 判断子序列

s = "abc"
t = "ahbgdc"

class Solution: (error)
    def isSubsequence(self, s: str, t: str):
        for i in range(len(s)):
            if  s[i] in t:
                if i <= t.index(s[i]) :
                   return  s;
                else:
                    return false
class Solution2:(error)
def isSubsequence(self, s: str, t: str) -> bool:
for i in range(len(s)):
if s[i] in t:
if i < len(s)-1 :
# if t.index(s[i]) <= t.index(s[i+1]):
if t.index(s[i]) < t.index(s[1+i]):
if i== len(s)-2 :
print("run here")
return True
else:
print("error")
return False
return False
 
class Solution3:(ture)
    def isSubsequence(self, s: str, t: str) -> bool:
        m,n = len(s),len(t)
        k,l=0,0
        while  k < m and  l <  n :
            if s[k] == t[l]:
                k+=1
            l+=1
        if k== m:
            return True
        else:
            return False

你可能感兴趣的:(Python 判断子序列)