392. 判斷子序列

我總會把問題想的很複雜到最後做不出來,嘖嘖嘖,咋辦呢

```c++

class Solution {
public:
bool isSubsequence(string s, string t) {
    if(s.empty())
        return true;
    int scount=0;
    for(int i=0;i<(int)t.length();++i)
    {
        if(t[i]==s[scount])
        {
            ++scount;
            if(scount == (int)s.length())
              return true;
        }
    }
    return false;
}
};

```

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章