• palindrome-partitioning-ii leetcode C++


    Given a string s, partition s such that every substring of the partition is a palindrome.

    Return the minimum cuts needed for a palindrome partitioning of s.

    For example, given s ="aab", Return1since the palindrome partitioning["aa","b"]could be produced using 1 cut.

    C++

    class Solution {
    public:
        int minCut(string s) {
            int n = s.size();
            if(n < 2) return 0;
            vector<int> dp(n, INT_MAX);
            vector<bool> tmp(n, false);
            vector<vector<bool> > p(n, tmp);
            for(int i=0; i<n; i++){
                for(int j=i; j>-1; j--){
                    if(s[i] == s[j] && (i-j < 2 || p[j+1][i-1])){
                        p[j][i] = true;
                        dp[i] = min(dp[i], j == 0? 0 : dp[j-1] + 1);
                    }
                }
            }
            return dp.back();
        }
    };
  • 相关阅读:
    PyQT_Group
    单例模式演示-1-39-07
    RSqlBuilder
    RExcel
    RJson
    NodeJs开发目录
    NodeJs事件驱动
    NodeJs实用工具util
    NodeJs之global,process
    NodeJs两个简单调试技巧
  • 原文地址:https://www.cnblogs.com/vercont/p/10210271.html
Copyright © 2020-2023  润新知