leetcode -- Palindrome Partitioning II
2014-10-06 23:13
288 查看
指责别人,看清自己
[问题描述]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",
Return
1since the palindrome partitioning
["aa","b"]could be produced using 1 cut.
[解题思路]
ans[i]表示s[i]至最后需要的划分数
注意:line6 "<="
int Solution::minCut(string s){ const int len = s.length(); bool pali[len][len]; int ans[len]; fill_n(&pali[0][0], len*len, false); for (int i = 0; i <= len; i++) ans[i] = len - i - 1; for (int i = len - 1; i >= 0; i --){ for (int j = i; j < len; j ++){ pali[i][j] = s[i]==s[j]&&(j-i<2||pali[i+1][j-1]); pali[i][j] == true?(ans[i] = min(ans[i], ans[j + 1] + 1)):(true); } } return ans[0]; }
相关文章推荐
- LeetCode-Palindrome Partitioning II-回文分割-DP优化
- LeetCode-Palindrome Partitioning II
- 【leetcode】Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning II, Solution
- LeetCode Palindrome Partitioning II
- [LeetCode 132] - 回文分割II(Palindrome Partitioning II)
- [leetcode]Palindrome Partitioning II
- LeetCode - Palindrome Partitioning I && II
- LeetCode 132 Palindrome Partitioning II
- leetcode之 Palindrome Partitioning I&II
- 【leetcode】Palindrome Partitioning II(hard) ☆
- LeetCode 132 Palindrome Partitioning II--In C++
- [Leetcode]Palindrome Partitioning II
- [Leetcode] Palindrome Partitioning II
- 【LeetCode】Palindrome Partitioning II 解题报告
- leetcode Palindrome Partitioning II
- Leetcode--Palindrome Partitioning II
- [leetcode]Palindrome Partitioning II
- Palindrome Partitioning II - Leetcode
- [LeetCode] Palindrome Partitioning II