Leetcode 132. Palindrome Partitioning II
来源:互联网 发布:python 量化 书籍 编辑:程序博客网 时间:2024/05/22 07:41
public int minCut(String s) {
int min = 0;
int len = s.length() ;
boolean[][] matrix = new boolean[len][len];
int[] cuts = new int[len + 1];
if (s.length() == 0 || s == null) {
return min;
}
for (int i = 0; i <=len; i++) {
cuts[i] = len - i-1 ;
}
for (int i = len - 1; i >= 0; i--) {
for (int j = i; j < len; j++) {
if((s.charAt(i) == s.charAt(j) && j-i<2)
|| (s.charAt(i) == s.charAt(j) && matrix[i + 1][j - 1])) {
matrix[i][j] = true;
cuts[i] = Integer.min(cuts[i], cuts[j + 1] + 1);
}
}
}
min=cuts[0];
return min;
}
阅读全文
0 0
- 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
- 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】132.Palindrome Partitioning II
- Leetcode 132. Palindrome Partitioning II
- LeetCode 132. Palindrome Partitioning II
- leetcode 132. Palindrome Partitioning II
- LeetCode : Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- windows核心编程之进程(1)
- linux上安装redis
- 有关linux下redis overcommit_memory的问题
- Spring Cloud Zuul
- 线程安全的遍历list
- Leetcode 132. Palindrome Partitioning II
- linux重置mysql密码
- 神经网络与深度学习(6)
- 洛谷Oj-平面上的最接近点对-分治
- 1059. C语言竞赛(20)
- linux里的backlog详解
- sizeof Class类的对象的大小
- 关于CNN减少参数个数原理的理解
- tensorflow-gpu环境的两种安装方式