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
碉堡了,可以用动规,但是如果存储n*m的表的话会爆内存,可以用2*m的表存,也可以回溯法,存储star的位置,后面不匹配的话就回退到star的位置重新匹配。
1 class Solution { 2 //if strlen is used, then it will be TLE 3 //iteration based solution 4 public: 5 bool isMatch(const char *s, const char *p) { 6 bool star = false; 7 const char *starPos = NULL; 8 const char *savePos = NULL; 9 while (*s != '