C++ Solution by Greedy


  • 0
    Y
    class Solution {
    public:
        bool isSubsequence(string s, string t) {
            int pos = 0;
            for(int i = 0; i < s.length(); ++i)
            {
                bool is_match = false;
                for(int j = pos; j < t.length(); ++j)
                {
                    if(t[j] == s[i]){
                        pos = j + 1;
                        is_match = true;
                        break;
                    }
                }
                if(!is_match) return false;
            }
            return true;
        }
    };
    

Log in to reply
 

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