LeetCode-Palindrome Partitioning II
2013-08-22 16:34
246 查看
class Solution { public: int minCut(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function if (s.size() == 0) { return 0; } vector<vector<bool> > F(s.size(), vector<bool>(s.size(), false)); for (int i = s.size() - 1; i >= 0; --i) for (int j = i; j < s.size(); ++j) F[i][j] = s[i] == s[j] && (j - i < 2 || F[i + 1][j - 1]); vector<int> minCnt(s.size(), 0); for (int i = 1; i < s.size(); ++i) { if (F[0][i]) { minCnt[i] = 0; } else { int curMin = i; for (int j = 1; j <= i; ++j) { if (F[j][i]) { curMin = min(curMin, minCnt[j - 1] + 1); } } minCnt[i] = curMin; } } return minCnt[s.size() - 1]; } };
相关文章推荐
- Palindrome Partitioning II Leetcode Python
- 【leetcode】Palindrome Partitioning II
- 每日AC-LeetCode-palindrome-partitioning-ii --动态规划
- Palindrome Partitioning II Leetcode
- 【LeetCode】Palindrome Partitioning I && II
- leetcode Palindrome Partitioning II
- Leetcode Palindrome Partitioning II
- LeetCode-Palindrome Partitioning II
- [leetcode]Palindrome Partitioning II
- LeetCode132 Palindrome Partitioning II&I
- LeetCode Palindrome Partitioning II
- [leetcode刷题系列]Palindrome Partitioning II
- 分割成回文需要的最小分割数 Palindrome Partitioning II @LeetCode
- leetcode Palindrome Partitioning II
- Leetcode--Palindrome Partitioning II
- 【LeetCode】Palindrome Partitioning II
- LeetCode Palindrome Partitioning, Palindrome Partitioning II
- LeetCode 132 Palindrome Partitioning II
- LeetCode-Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning II