leetcode 132. Palindrome Partitioning II ----- java
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.
public class Solution {
public int minCut(String s) { int len = s.length();
if( len <= 1)
return 0;
char[] word = s.toCharArray();
int[] dp = new int[len];
boolean[][] isPalindrome = new boolean[len][len];
for( int i = 0;i<len;i++){
int min = i;
for( int j = 0;j<=i;j++){
if( word[i] == word[j] && ( j+1>=i-1 || isPalindrome[j+1][i-1] )){
isPalindrome[j][i] = true;
min = j==0?0:Math.min(min,dp[j-1]+1);
}
}
dp[i] = min;
} return dp[len-1];
} }
leetcode 132. Palindrome Partitioning II ----- java的更多相关文章
- Java for LeetCode 132 Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- Leetcode 132. Palindrome Partitioning II
求次数的问题一般用DP class Solution(object): def minCut(self, s): """ :type s: str :rtype: int ...
- leetcode 131. Palindrome Partitioning 、132. Palindrome Partitioning II
131. Palindrome Partitioning substr使用的是坐标值,不使用.begin()..end()这种迭代器 使用dfs,类似于subsets的题,每次判断要不要加入这个数 s ...
- 【LeetCode】132. Palindrome Partitioning II
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- 【leetcode】Palindrome Partitioning II
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- 【leetcode】Palindrome Partitioning II(hard) ☆
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 132. Palindrome Partitioning II
题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...
- [LeetCode] 132. Palindrome Partitioning II_ Hard tag: Dynamic Programming
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 132. Palindrome Partitioning II (String; DP)
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
随机推荐
- Linux-Gcc生成和使用静态库和动态库详解
一.基本概念 1.1什么是库 在windows平台和linux平台下都大量存在着库. 本质上来说库是一种可执行代码的二进制形式,可以被操作系统载入内存执行. 由于windows和linux的平台不同( ...
- DotNetBar v12.6.0.4 Fully Cracked
更新信息: http://www.devcomponents.com/customeronly/releasenotes.asp?p=dnbwf&v=12.6.0.4 如果遇到破解问题可以与我 ...
- 记录一些容易忘记的属性 -- UIKeyboard
//UIKeyboardWillShowNotification这个通知在软键盘弹出时由系统发送 //UIKeyboardWillShowNotification 通知:键盘将要显示的通知 ...
- C/C++学习之基础-001
1.C++虚函数的工作原理 虚函数(virtual function)需要虚函数表(virtual table)才能实现.如果一个类有函数声明成虚拟的,就会生成一个虚函数表,存放这个类的虚函数地址.若 ...
- SimpleDateFormat格式化日期
SimpleDateFormat格式化日期 import java.text.SimpleDateFormat;import java.util.Date;public class test { pu ...
- ACM -二分图题目小结
暂时只包括与最大匹配相关的问题. 求最大独立集,最小路径覆盖等等大多数题目都可以转化为求最大匹配用匈牙利算法解决. 1.最大匹配(边集) 此类问题最直接,直接用匈牙利算法即可. HDU 2063 过 ...
- GCD的用法
单例的实现 + (BindingRedResourceWIndow *)sharedInstance { static id sharedInstance = nil; static dispatch ...
- Java中的接口与抽象类
抽象类很简单,就是多了个abstract关键字,可以有(也可以没有)只声明不定义的方法.不能实例化该类. 接口比较特殊: 无论你加不加public,接口中声明的方法都是public的,还有无论你加不加 ...
- task2
1. 邮件修改Mailtemplatereportfieldlink带<>的都改翻译${MAWBTask} 2.测试发邮件 3.找出能做成模版的所有地方,改成模版,复杂的地方记录下来
- Linux----七个有效的文本编辑习惯
如果你要花大量的时间键入文本, 写程序或编写HTML脚本, 你可以通过有效地使用一个好的编辑器来替你节省时间. 本文将引导你如果快速地完成你的编辑工作, 并且减少你的错误. 本文将以开放源码软件Vim ...