Share my C++ solution, very easy to understand


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

Log in to reply
 

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