'?' 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("aabool isMatch(string s, string p) { int Slen=s.length(),Plen=p.length(),i,j,iStart=-1,jStart=-1; for(i=0,j=0;i<Slen;++i,++j) { if(p[j]=='*') { iStart=i; jStart=j; --i; } else { if(p[j]!=s[i] && p[j]!='?') { if(iStart>=0) { i=iStart++; j=jStart; } else return false; } } } while(p[j]=='*') ++j; return j==Plen; }
44. Wildcard Matching
最新推荐文章于 2020-07-05 09:55:56 发布