题目
代码
class Solution {
public int countSubstrings(String s) {
int n = s.length();
boolean[][] dp = new boolean[n][n];
int count=0;
for(int j=0;j<n;j++) {
for(int i=0;i<=j;i++) {
if(s.charAt(j)==s.charAt(i)) {
//判断回文串有三种情况:本身和本身相等;ab=ba;axxxa且xxx为回文串
if( dp[i][j] = (i==j || j-i==1 || dp[i+1][j-1]) ) count++;
}
}
}return count;
}
}