TAG: STR LSE LAN BLE with XPL SSI public color
That's so hard, https://leetcode.com/problems/regular-expression-matching/discuss/180290/JAVA-DP-solution-with-detailed-explanation.
1 classSolution {2 Public BooleanIsMatch (String s, String p) {3 Boolean[] DP =New Boolean[S.length () +1] [P.length () +1];4Dp[0][0] =true;5 for(inti = 1; I <= p.length (); i++){6 if(P.charat (i-1) = = ' * ' && dp[0][i-2]){7Dp[0][i] =true;8 }9 }Ten One for(inti = 1; I <= s.length (); i++){ A for(intj = 1; J <= P.length (); J + +){ - if(S.charat (i-1) = = P.charat (j-1) | | P.charat (j-1) = = '. '){ -DP[I][J] = dp[i-1][j-1]; the}Else if(P.charat (j-1) = = ' * '){ - if(P.charat (j-2)! = S.charat (i-1) && P.charat (j-2)! = '. '){ -DP[I][J] = dp[i][j-2]; -}Else{ +DP[I][J] = Dp[i][j-1] | | DP[I-1][J] | | Dp[i][j-2]; - } + } A } at } - returndp[s.length ()][p.length ()]; - - } -}
Ten. Regular Expression Matching