递归写法
class Solution {
public boolean isMatch(String s, String p) {
if(s.length() == 0){
if(p.length()%2 !=0 ) return false;
for(int i=1; i<p.length(); i+=2){
if(p.charAt(i) != '*') return false;
}
return true;
}
if(p.length()==0) return false;
char c0 = s.charAt(0), c1 = p.charAt(0), c2 = '2';
if(p.length()>1) c2 = p.charAt(1);
if(c2!='*'){
if(c0==c1||c1=='.') return isMatch(s.substring(1),p.substring(1));
else return false;
}else {
if(c0==c1||c1=='.') return isMatch(s.substring(1),p) || isMatch(s,p.substring(2));//指的是星号前当做一次,还是整个星号当做0次
else return isMatch(s,p.substring(2));
}
}
}
好委屈,但是只能自我排解