http://www.lintcode.com/zh-cn/problem/wildcard-matching/
class Solution {
public:
/**
* @param s: A string
* @param p: A string includes "?" and "*"
* @return: A boolean
*/
bool isMatch(const char *s, const char *p) {
// write your code here
const char*str, *ptr;
bool start = false;
const char* i = p;
int k = 0;
for (str = s, ptr = p; *str != '\0'; str++, ptr++){
if (*ptr == '?'){
start = false; continue;
}
else if (*ptr == '*'){
start = true;
i = ptr;
while (*ptr == '*')ptr++;
if (*ptr == '\0')return true;
str--;
ptr--;
}
else {
if (*ptr != *str){
if (k == 0)return false;
if (!start){ ptr = i; }
ptr--;
}else
start = false;
}
k++;
}
while (*ptr == '*')ptr++;
return *ptr == '\0';
}
};