I can't think of a better solution than this. Getting run time error

'*' can match with empty string

for ( int j = 1; j <= m; j++)

if (pattern[j - 1] == '*' )

`lookup[0][j] = lookup[0][j-1]

You are not checking this case and if you want to look a simpler solution Google wildcard matching. YouTube and various other sites have a really good tutorial.

I have changed my code. It’s passing all test cases except now except tc 2 where is says runtime error. I submitted my code on leetcode, it is getting accepted there.
Please edit my code if necessary
https://ide.codingblocks.com/s/243885

In line no.47 if value of j= 1 and you are trying to access J-2 then you will definitely get a runtime error

Yeah you are right. That was the problem. It got submitted but I still have a doubt. Is “*a” a valid pattern for input?

It is a right input.

Actually in my accepted code, I am not checking for the case where the first character is ’ * ’ that’s why I am confused. All I can make out is that a ’ * ’ as the first character of the string is same as an empty string.


Accepted code

Oh maybe the test cases are not strong. Doesn’t matter good job. Atleast you observe these things.

1 Like