Palindrome Partitioning II - Leetcode
来源:互联网 发布:诺基亚5320手电筒软件 编辑:程序博客网 时间:2024/06/10 05:49
是第一个的衍生,DP的重复使用
第一个DP是记录i到j是否是回文;于此同时另一个DP是记录i到j需要最小的隔板数目。
这里需要注意的是第二个DP的思想r[i]=min{r[i],r[j+1]+1}这个深层次的思想是,或许当前默认的cut数目或者是第j+1个位置的cut数目加1.
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[] r=new int[s.length()+1]; for(int i=0; i<r.length; i++) r[i]=r.length-2-i; boolean[][] f=new boolean[s.length()][s.length()]; for(int i=s.length()-1; i>=0; i--) for(int j=i; j<s.length(); j++){ if(s.charAt(i)==s.charAt(j)&&(j-i<=1 || f[i+1][j-1]==true)){ f[i][j]=true; r[i] = Math.min(r[i],r[j+1]+1); } } return r[0]; }}
0 0
- LeetCode : Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- leetcode:Palindrome Partitioning II
- 【leetcode】Palindrome Partitioning II
- leetcode - Palindrome Partitioning II
- [LeetCode]Palindrome Partitioning II
- [Leetcode]Palindrome Partitioning II
- [leetcode]Palindrome Partitioning II
- leetcode Palindrome Partitioning II
- LeetCode-Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- LeetCode - Palindrome Partitioning II
- [Leetcode]Palindrome Partitioning II
- 【leetcode】Palindrome Partitioning II
- LeetCode Palindrome Partitioning II
- [leetcode]Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning II
- 领导力的塑造——Leo鉴书85
- 中国领导文化
- Palindrome Partitioning - Leetcode
- UVAOJ 127-"Accordian " Patience | java实现
- YT14-HDU-Eddy的彩票
- Palindrome Partitioning II - Leetcode
- js select的语法
- 欢迎使用CSDN-markdown编辑器
- delphi各个版本编译开关值
- sentence structures经典句型
- 一个好用的程序编辑软件Sublime Text 3
- 如何同时启动多个Tomcat服务器
- MySQL 技巧
- mysql定时任务