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
算法来自http://blog.unieagle.net/2012/11/07/leetcode%E9%A2%98%E7%9B%AE%EF%BC%9Awildcard-matching/
使用贪心法,首先按*将p串分割成各个不含*的子串,对于串头无*的子串必须从字符串头匹配,串尾无*的子串必须从字符串尾开始匹配,其他子串按顺序匹配即可

class Solution { public: vector<string> GenPattern(const char* p,bool& first,bool&last){ vector<string> ret; if(p[0]=='