Implement wildcard pattern matching with support for '?'
and '*'
.
'?' 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
实现两个通配符?和*
?:可以匹配任意单一的字符
* :可以匹配任意长度的字符串(包括空串)
思路1:动态规划
这个题其实有点像“编辑距离”的问题,可以根据两个字符串的长度mn(m=s.size();n=p.size()),划分成一个(n+1)*(m+1)的编辑矩阵record,也是