
###392. Is Subsequence


题目:
<https://leetcode.com/problems/is-subsequence/>


难度:

Medium


思路


follow up question很有意思


最naive的思路表现形式如下：

超时

```
class Solution(object):
    def isSubsequence(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        if s == "": return True
        for i in xrange(len(t)):
        	if t[i] == s[0]:
        		return self.isSubsequence(s[1:],t[i+1:])

        return False
```

因为直接操作string的昂贵以及递归的昂贵

同样的思路


```
class Solution(object):
    def isSubsequence(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        if s == "" : return True

        ps, pt = 0, 0 
        lens, lent = len(s), len(t)
        while ps < lens and pt < lent:
        	if s[ps] == t[pt]:
        		ps += 1
        		pt += 1
        	else:
        		pt += 1

        return ps >= lens
```

AC


