leetcode网站维护,只能去力扣了

class Solution {
    public boolean isMatch(String s, String p) {
        boolean[][] dp = new boolean[p.length() + 1][s.length() + 1];
        dp[0][0] = true;
        for(int i = 1; i < p.length() + 1; ++i){
            if(p.charAt(i - 1) == '*' && dp[i - 1][0] == true){
                dp[i][0] = true;
            }
        }

        for(int i = 1; i < p.length() + 1; ++i){
            if(p.charAt(i - 1) == '*'){
                for(int j = 1; j < s.length() + 1; ++j){
                    if(dp[i][j - 1] == true || dp[i - 1][j - 1] == true || dp[i - 1][j] == true){
                        dp[i][j] = true;
                    }
                }
            }else{
                for(int j = 1; j < s.length() + 1; ++j){
                    if(p.charAt(i - 1) == '?' || s.charAt(j - 1) == p.charAt(i - 1)){
                        if(dp[i - 1][j - 1] == true){
                            dp[i][j] = true;
                        }
                    }
                }
            }
        }
        return dp[p.length()][s.length()];
    }
}
08-10 17:29