O(N) C solution


  • 0
    M
    bool isSubsequence(char* s, char* t) {
        if (*s == '\0') return true;
        char *p = s;
        while(*t != '\0'){
            while (*p != '\0' && *t != '\0' && *p == *t){t++; p++;}
            if (*p == '\0') return true;
            t++;
        }
        return false;
    }
    

Log in to reply
 

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