C++_72ms_97.52%


  • 0

    //Very similar with the most common answer.

    class Solution {
    public:
    bool isSubsequence(string s, string t) {
        int ns = s.size();//sample
        int nt = t.size();//orginal
        int i = 0, j = 0;
        for(; i < ns && j < nt;j++){
            if(s[i] == t[j]){i++;}
            if(nt - j < ns - i) return false;
        }
        return i == ns;
    }   };
    

    0_1474561522378_387449AC-ADBC-4067-941A-9A115234620D.png


  • 0
    X

    It is a GREAT idea that you post proof of runtime


Log in to reply
 

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