-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Bug Report for https://neetcode.io/problems/regular-expression-matching
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
s="aab"
p="cab"
correct output should be false but it is true
my code
class Solution {
public:
int n,m;
bool solve( int i, int j, string &s, string &p){
if( i <0 && j<0 ) return true;
if( j<0 && i >=0 ) return false;
else if( i<0 && j>=0){
while(j>=0 && p[j]=='*')j--;
return j==-1?true:false;
}
bool f= false;
if(s[i]==p[j] || p[j]=='.') return f=f| solve( i-1, j-1, s,p);
else if( p[j]=='*'){
return f=f| solve( i-1,j, s,p)|solve( i, j-1, s,p);
}
return f;
}
bool isMatch(string s, string p) {
n=s.size();
m= p.size();
return solve( n-1,m-1, s,p);
}
};

Metadata
Metadata
Assignees
Labels
No labels