Palindrome Partitioning II
来源:互联网 发布:mdf文件恢复数据库 编辑:程序博客网 时间:2024/05/17 04:19
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 1
since the palindrome partitioning ["aa","b"]
could be produced using 1 cut.
class Solution {public: int minCut(string s) { int n = s.length(); if (n < 1) { return 0; } bool isPal[n][n];//记录从i到j之间的字符串是否为回文 memset(isPal, false, n*n*sizeof(bool)); int cut[n];//记录从0到i的字符串的最小切割数量 cut[0] = 0; for (int i = 1; i < n; i++) { cut[i] = cut[i-1] + 1; for (int j = 0; j <= i; j++) { if (s[i] == s[j] && (i-j < 2 || isPal[j+1][i-1])) { isPal[j][i] = true; if (j == 0) { cut[i] = 0; } else if (cut[j-1]+1 < cut[i]) { cut[i] = cut[j-1] + 1; } } } } return cut[n-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
- uva12075 Counting Triangles
- CAGradientLayer与CAShapeLayer实现不同颜色画圆动画(Spark相机的录制的效果)
- Dart是一个怎样的语言?
- 更换IP地址方法简介
- BZOJ4006【斯坦纳树】
- Palindrome Partitioning II
- 复制自身程序到windows目录和系统目录下
- 欢迎使用CSDN-markdown编辑器
- java项目管理经验总结
- 将w32 dll文件以资源的形式加载,并且在内存中调用
- CVX coding
- 开始刷leetcode day3: house robber
- iOS- 传感器用法简介
- 百万宝贝观后感