Simple to understand C code


  • 0
    S
    bool isSubsequence(char* s, char* t) {
        int sizes=strlen(s);
        int sizet=strlen(t);
        int i,j;
        int tcash=0;
        if(t==NULL||sizet==0){
            if(sizes==0){
                return true;
            }
            return  false;
        }
        for(i=0;i<sizes;i++){
            j=tcash;
            if(tcash>=sizet){
                return false;
            }
            while(j<sizet){
                if(s[i]==t[j]){
                    tcash=j+1;
                    break;
                }
                if(j==sizet-1)
                {
                    return false;
                }
                j++;
            }
        }
        return true;
    }
    

Log in to reply
 

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