Implement regular expression matching with support for ‘.‘
and ‘*‘
.
‘.‘ Matches any single character. ' * ' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be:bool IsMatch (const char *s, const char *p) Some examples:ismatch ("AA", "a") →falseismatch ( "AA", "AA") →trueismatch ("AAA", "AA") →falseismatch ("AA", "A *") →trueismatch ("AA", ". *") →trueismatch ("AB", ". *") →true IsMatch ("AaB", "C*a*b") →true
1 BOOLIsMatch (Const Char*s,Const Char*p)2 {3 if(*p = =' /') 4 return(*s = =' /');5 6 if(* (p+1) =='*')7 {8 while(*p = = *s | | (*p = ='.'&& *s! =' /'))9 {Ten if(IsMatch (s++, p+2)) One return true; A } - returnIsMatch (S, p+2); - } the Else - { - if(*p = = *s | | (*p = ='.'&& *s! =' /')) - returnIsMatch (s+1, p+1); + return false; - } +}
Leetcode 10. Regular Expression Matching