C++ Solution | Time Complexity - O(min(m,n))


#1

int Solution::isMatch(const string A, const string B) {
if(A==B)
return 1;
int n=A.size();
int m= B.size();

int i=n-1, j=m-1;

while(i>=0 && j>=0)
{
    if(A[i]!=B[j] && B[j]!='.')
    {
        if(B[j]=='*')
        {
            if(B[j-1] == A[i] || B[j-1] == '.')
            {
                i--;
                continue;
            }
            else
            {
                j=j-2;
                continue;
            }
        }
        return 0;
    }
    else
    {
        i--; j--;
    }
}
if(i>=0)
    return 0;
return 1;

}