leetcode 392 Is Subsequence C++

来源:互联网 发布:网络购物英文翻译 编辑:程序博客网 时间:2024/04/29 23:37

这道题没什么说的,双指针即可。

有一点需要注意的是,size()方法挺耗时间的,我直接用打败14%,只用一次打败91%

    bool isSubsequence(string s, string t) {        int sSize = s.size();        int tSize = t.size();        if (!sSize) return true;        int indexS = 1;        int indexT = 1;        while(indexS <= sSize && indexT <= tSize) {            if (s[indexS] == t[indexT]) {                indexS++;            }            indexT++;        }        if (indexS == sSize + 1) return true;        return false;    }


0 0
原创粉丝点击