一开始用深度优先,超时
然后觉得是深度遍历过的没有记录结果,开了个vector<vector<int>> 内存超出界限
倒数第三个题目,懒得纠结了,就网上找解决方案
虽然不喜欢goto,但是不管了。
class Solution {
public:
bool isMatch(const char *s, const char *p) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
bool isStar=false;
int i;
startLoop:
for(i=0;s[i];i++)
{
switch(p[i])
{
case '?':break;
case '*':
p+=i;
s+=i;
isStar=true;
while(*p=='*') p++;
if(!(*p)) return true;
goto startLoop;
default:
if(s[i]!=p[i]) goto check;
}
}
while(p[i]=='*') p++;
return (!p[i]);
check:
if(isStar) {s++;goto startLoop;}
return false;
}
};