---
# System prepended metadata

title: Leetcode 392.

---

# Leetcode 392. Is Subsequence

## 題解

### Two pointers

```python
class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        # Brute force
        # Time complexity: O(t+s)
        # Space complexity: O(1)
        tn = len(t)
        sn = len(s)
        cs = sn - 1
        ct = tn - 1
        while 0 <= ct < tn and 0 <= cs < sn:
            st = t[ct]
            top_s = s[cs]
            if st == top_s:
                cs -= 1
            ct -= 1
        return cs == -1
```