Python method str.index


  • 1
    L
    def isSubsequence(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        idx = -1
        try:
            for c in s:
                idx = t.index(c, idx+1)
            return True
        except ValueError:
            return False

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.