题目:(这题好难。题目意思类似于第十题,只是这里的*就是可以匹配任意长度串,也就是第十题的‘.*’)
'?' 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 class Solution {
2 public:
3 bool isMatch(const char *s, const char *p)
4 {
5 while(p + 1 != NULL && *(p+1) == *p && *p == '*') p++;
6 if (*p == '