Simple C++ solution


  • 0
    P
    class Solution {
    public:
        bool isSubsequence(string s, string t) {
            int i = 0;
            int j = 0;
            
            while(i < t.length() && j < s.length()) {
                if(t[i] == s[j]) {
                    j++;
                }
                i++;
            }
            
            if(j == s.length())
                return true;
            return false;
        }
    };
    

Log in to reply
 

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