Skip to content

Bug Report for regular-expression-matching #5124

@cyrusverma

Description

@cyrusverma

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);

    
}

};

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions