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") → false isMatch("aa","aa") → true isMatch("aaa","aa") → false isMatch("aa", "a*") → true isMatch("aa", ".*") → true isMatch("ab", ".*") → true isMatch("aab", "c*a*b") → true
思路:对于字符串匹配,s[i]和p[j].此题的关键就在于p[j+1]是否为'*'.递归思路解题。
如果p[j+1]!='*',s[i]==p[j],则匹配下一位(i+1,j+1),如果s[i]!=p[j],匹配失败
如果p[j+1]=='*',s[i]==p[j],则匹配(i,j+2)或者(i+1,j+2),如果s[i]!=p[j],则匹配(i,j+2)
class Solution { public: bool isMatch(const char *s, const char *p) { if(*p=='