leetcode 132: Palindrome Partitioning II
来源:互联网 发布:暗影格斗2mac破解 编辑:程序博客网 时间:2024/06/06 03:06
Use two dp array, dp[i][j] means whether s[j...i] is a palindrome and cut[i] means the min cut before index i.
class Solution {public: int minCut(string s) { int len=s.length(); vector<bool> a(len,0); vector<vector<bool> > dp(len,a); vector<int> cut(len+1); for(int i=0;i<=len;i++) cut[i]=i-1; for(int i=0;i<len;i++) for(int j=i;j>=0;j--) { if(i-j<2) dp[i][j]=s[i]==s[j]; else dp[i][j]=s[i]==s[j]&&dp[i-1][j+1]; if(dp[i][j]) cut[i+1]=min(cut[i+1],cut[j]+1); } return cut[len]; }};
0 0
- LeetCode: Palindrome Partitioning II [132]
- LeetCode 132 Palindrome Partitioning II
- Leetcode(132) Palindrome Partitioning II
- [leetcode 132] Palindrome Partitioning II
- leetcode || 132、Palindrome Partitioning II
- leetcode 132: Palindrome Partitioning II
- 132 Palindrome Partitioning II [Leetcode]
- LeetCode #132: Palindrome Partitioning II
- Leetcode 132 Palindrome Partitioning II
- LeetCode 132 Palindrome Partitioning II
- LeetCode : Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- leetcode:Palindrome Partitioning II
- 【leetcode】Palindrome Partitioning II
- leetcode - Palindrome Partitioning II
- [LeetCode]Palindrome Partitioning II
- [Leetcode]Palindrome Partitioning II
- [leetcode]Palindrome Partitioning II
- 素数的判定
- 使用git-flow来帮助管理git代码
- hdu1874 畅通工程续 最短路 floyd或dijkstra或spfa
- C. Arthur and Table(Codeforces Round #311 (Div. 2) 贪心)
- ViewPager禁用左右滑动
- leetcode 132: Palindrome Partitioning II
- object hbase is not a member of package org.apache.hadoop
- Java中enum的学习总结
- Amazon Kinesis简介
- Facade——结构模式
- JAVA学习(十)__MessageFormat用法
- 每日五道题(struts2)
- Leetcode 211 Add and Search Word - Data structure design
- CXF+spring构建restful风格的webservice