Palindrome Partitioning II
来源:互联网 发布:两组数据差值的标准差 编辑:程序博客网 时间:2024/06/08 12:24
class Solution {public:bool** isPal;bool isPalindrome(int start,int end,const string& s){int len=(end-start)/2;for(int i=0;i<len;++i){if(s[start+i]!=s[end-1-i]){return false;}}return true;} int minCut(string s) { int len=s.size();//cout<<"start to fill matrix"<<endl;isPal=new bool*[len+1];for(int i=0;i<=len;++i){isPal[i]=new bool[len+1]();}for(int i=0;i<len;++i){isPal[i][i]=true;}for(int k=1;k<=len;++k){for(int i=0;i+k<len;++i){int j=i+k;if(s[i]==s[j]){if(i+1>=j-1){isPal[i][j]=true;}else if(isPal[i+1][j-1]){isPal[i][j]=true;}else{//remain false}}}}cout<<"end to fill matrix"<<endl;//int *dp2=new int[len+1]();dp2[0]=1;for(int i=1;i<len;++i){int min=dp2[i-1]+1;for(int j=i-1;j>=0;--j){if(isPal[j][i]){if(j==0){min=1;}else if(dp2[j-1]+1<min){min=dp2[j-1]+1; }else{//no else exist}}}dp2[i]=min;/*if(min==len+1){dp2[i]=dp2[i-1]+1;}else{dp2[i]=min+1;}*/}return dp2[len-1]-1; }};
0 0
- LeetCode : Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- leetcode:Palindrome Partitioning II
- Palindrome Partitioning II
- 【leetcode】Palindrome Partitioning II
- Palindrome Partitioning II
- leetcode - Palindrome Partitioning II
- Palindrome Partitioning II
- Palindrome Partitioning II
- [LeetCode]Palindrome Partitioning II
- [Leetcode]Palindrome Partitioning II
- [leetcode]Palindrome Partitioning II
- Palindrome Partitioning II
- leetcode Palindrome Partitioning II
- Palindrome Partitioning II
- LetCode:Palindrome Partitioning II
- LeetCode-Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- Eclipse用svn管理Android项目问题
- 忘记NSURLConnection,拥抱NSURLSession吧!
- 跟名站学前端之mcdonalds
- Remove Duplicates from Sorted List
- Convert Sorted List to Binary Search Tree
- Palindrome Partitioning II
- 关于图的邻接表定义的解释
- 云存储“T时代”:云空间推出1T免费空间
- Climbing Stairs
- C. Vanya and Exams
- 使用Nginx的proxy_cache缓存功能取代Squid[原创]
- PHP参数修改不生效的问题
- 如何判断$_POST传送的<textarea>标签中的值是否为空
- Reorder List