题目
‘?’ Matches any single character.
‘*’ Matches any sequence of characters (including the empty sequence).
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”, “*”) → true
isMatch(“aa”, “a*”) → true
isMatch(“ab”, “?*”) → true
isMatch(“aab”, “c*a*b”) → false
思路
此题和第十题 Regular Expression Matching极为相像,只不过这个题‘*’可代表任意字符串,而10题只能表示若干个前面字母。举例来说,此题中*可以表示a,ab,abdfefa等,也可以表示空。但10题中*不可以单独出现,其必须和它前面的字母共同构成一个表达式,比如说a*表示若干个a,也即a,aa,aaa,或空。
仍然采用DP,设置一个vectorre(n+1),存放第一个字符串截止到该位置的匹配情况,然后从第二个字符串开始遍历,遇到*要特殊处理,对于字符串2的每一位,都要从字符串1中