similar to strstr


  • 0
    S

    No necessary to use DP, just compare char one by one.

        bool isSubsequence(string s, string t) {
            int i, j;
            for (i = 0, j = 0; i < s.length() && j < t.length(); j++)
                s[i] == t[j] ? i++ : 0;
            return i == s.length() && j <= t.length();
        }
    

Log in to reply
 

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