leetcode 647. Palindromic Substrings
题目描述
代码:
class Solution {
public:int countSubstrings(string s) {int n = s.size();//i<=j,dp[i][j]表示子字符串s[i,j]是否是回文子串,i>j的dp[i][j]不定义vector<vector<int>> dp(n,vector<int>(n,false));int res = 0;for(int i = n-1;i>=0;i--){for(int j = i;j <n;j++){if(s[i] == s[j]){if(j-i <=1){dp[i][j] = true;res++;}else if(dp[i+1][j-1] == true){dp[i][j] = true;res++;}}}}return res;}
};