zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    复杂对象创建终结者(Builder Pattern)
    创建型模式特立独行的两位大侠
    工厂模式(Factory)
    MAC 相关
    iOS 地图相关
    iOS字体相关
    App跳转系统设置界面
    Mac 模拟慢速网络
    Thread1:EXC_BAD_ACCESS 错误
    iOS 统计App 的代码总行数
  • 原文地址:https://www.cnblogs.com/z977690557/p/13388986.html
Copyright © 2011-2022 走看看