```
class Solution {
public:
bool isMatch(string s, string p) {
int n=s.length(), m=p.length();
int pid=0, sid=0;
int pidp=-1, sidp=-1;
while(sid<n){
if(p[pid]==s[sid] || p[pid]=='?'){
pid++; sid++;
}else if(p[pid]=='*'){
pidp=pid++; sidp=sid;
}else{
if(pidp>-1){
pid=pidp+1; sid=++sidp;
}else{
return false;
}
}
}
while(p[pid]=='*') pid++;
return pid==m;
}
};
```