https://www.cnblogs.com/grandyang/p/7404777.html

博客中写的<=2,实际上<=1也是可以的

相当于判断一个大指针内所有子字符串是否可能为回文

class Solution {
public:
    int countSubstrings(string s) {
        int length = s.size();
        int res = 0;
        vector<vector<bool>> dp(length+1,vector<bool>(length+1,false));
        for(int i = 1;i <= length;i++){
            for(int j = 1;j <= i;j++){
                if(s[i-1] == s[j-1]){
                    if(i -j <= 1 || dp[i-1][j+1]){
                        dp[i][j] = true;
                        res++;
                    }
                }                  
            }
        }
        return res;
    }
};

 

相关文章:

  • 2021-07-02
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
猜你喜欢
  • 2021-10-25
  • 2022-12-23
  • 2021-11-28
  • 2021-12-02
  • 2021-12-10
  • 2021-06-25
相关资源
相似解决方案