package com.mt.wsq.lc.dp;
public class IsMatch {
public boolean isMatch(String s, String p){
if (s == null && p == null){
return true;
}
if (s == null || p == null){
return false;
}
int m = s.length();
int n = p.length();
char[] sArr = s.toCharArray();
char[] pArr = p.toCharArray();
boolean[][] f = new boolean[m + 1][n + 1];
f[0][0] = true;
for (int i = 0; i <= m; i++){
for(int j = 1; j <= n; j++){
if (pArr[j - 1] == '*'){
f[i][j] = f[i][j-2];
if (matcher(sArr, pArr, i, j - 1)){
f[i][j] = f[i][j] || f[i-1][j];
}
}else{
if (matcher(sArr, pArr, i, j)){
f[i][j] = f[i-1][j-1];
}
}
}
}
return f[m][n];
}
public boolean matcher(char[] sArr, char[] pArr, int i, int j){
if (i == 0){
return false;
}
if (pArr[j-1] == '.'){
return true;
}
return sArr[i-1] == pArr[j-1];
}
}
|