题目:
解析:
状态表示+状态转移方程:
初始化+填表顺序+返回值:
代码:
public int minInsertions(String ss) {char[] s = ss.toCharArray();int n = s.length; int[][] dp = new int[n][n]; for(int i = n-1; i >= 0; i--){ // dp[0][i] = 0;for(int j = i+1; j < n; j++){if(s[i] == s[j]) dp[i][j] = dp[i+1][j-1];else dp[i][j] = Math.min(dp[i][j-1],dp[i+1][j])+1;}}return dp[0][n-1];}