What does match zero or more of previous occurrence mean?
Like for following input, I am giving output as 1
abbbcd
ab*cd
(ie, matching โbโ before * with 3 โbโ in the original string).
My code passes 3 cases and rest do not pass.
What does match zero or more of previous occurrence mean?
Like for following input, I am giving output as 1
abbbcd
ab*cd
(ie, matching โbโ before * with 3 โbโ in the original string).
My code passes 3 cases and rest do not pass.
That is if the previous character is c:
If c != โ.โ then match as many instances of c.
For example, โab*cdโ = {acd, abcd, abbcd, โฆ }
If c == โ.โ then the characcters can be anything
for example, โa.*cdโ = {acd, aacd, aaaaacd, absfud, โฆ }
I have updated the code, but getting MLE & WA for few cases.
Please share the code.
There are some issues. Take a look at this code, and try to implement on your own, elseโ Iโll help
bool isMatch(string s, string p) {
if (p.empty()) { return s.empty(); }
if ('*' == p[1])
// x* matches empty string or at least one character: x* -> xx*
// *s is to ensure s is non-empty
{
return (isMatch(s, p.substr(2)) || !s.empty() && (s[0] == p[0] || '.' == p[0])
&& isMatch(s.substr(1), p));
}
else {
return !s.empty() && (s[0] == p[0] || '.' == p[0]) && isMatch(s.substr(1), p.substr(1));
}
}
This is a bruteforce, for your help, you just take hints and write the optimized dp solution yourself.
It will be very helpful to you if you are able to write the code on your own.
If you have any doubts, feel free to reach back.
Implemented successfully.