public static boolean isMatch(String s, String p) {
char[] schar = s.toCharArray();
char[] pchar = p.toCharArray();
int slength = s.length();
int plength = p.length();
boolean[][] dp = new boolean[slength + 1][plength + 1];
dp[0][0] = true;
for (int j = 1; j < plength + 1; j++) {
if (pchar[j - 1] == '*') {
dp[0][j] = dp[0][j - 2];
}
}
for (int i = 1; i < slength + 1; i++) {
for (int j = 1; j < plength + 1; j++) {
if (pchar[j - 1] == '.') {
dp[i][j] = dp[i - 1][j - 1];
}
else if (pchar[j - 1] == '*') {
if (pchar[j - 2] == '.') {
if (dp[i][j - 2] || dp[i][j - 1] || dp[i - 1][j])
dp[i][j] = true;
}
else {
if (dp[i][j - 2] || dp[i][j - 1] || (schar[i - 1] == pchar[j - 2]
&& dp[i - 1][j]))
dp[i][j] = true;
}
}
else {
if (schar[i - 1] == pchar[j - 1])
dp[i][j] = dp[i - 1][j - 1];
}
}
}
return dp[slength][plength];
}