leetcode 392. Is Subsequence

Orignal question can be found here.

My solution is as follows:

int isSubsequence(char* s, char* t)
{
        int s_len=strlen(s);
        int t_len=strlen(t);
        if(s_len>t_len)
                return 0;
        if(s_len==0)
                return 1;

        for(int i=t_len-1; i>=0; --i)
        {
                if(s[s_len-1]==t[i])
                {
                        s[s_len-1]=t[i]=0;
                        return isSubsequence(s, t);
                }
        }
        return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *