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 ... 
随机推荐
- RM报表的打印偏移
			自己摸索一下 RMReport1.SaveReportOptions.AutoLoadSaveSetting := True; RMReport1.SaveReportOptions.UseRegis ... 
- Android 应用按两下返回键退出应用程序
			在android应用开发中,有时候应用会用到按两下返回键退出应用的功能,今天介绍一下这个功能,直接上代码: @Override public boolean dispatchKeyEvent(KeyE ... 
- java基础之  创建对象的几种方式
			有4种显式地创建对象的方式: 1.用new语句创建对象,这是最常用的创建对象的方式. 2.运用反射手段,调用java.lang.Class或者java.lang.reflect.Constructor ... 
- 【温故知新C/C++/opencv】取址符&||cv::groupRectangles||引用与值传递
			cv::groupRectangles void groupRectangles(vector<Rect>& rectList, int groupThreshold, doubl ... 
- matlab图形句柄属性总结
			原文在于雪漫的bloghttp://blog.sina.com.cn/s/blog_4b9b714a0100cce2.html这两天在看句柄式图形方面的东西,以下是我在看书过程中整理的学习笔记,比较详 ... 
- php注册审核显示
			用户进行注册,管理员通过审核后,使用户通过审核 数据库建表 create database mydb; use mydb; create table User ( Uid int auto_incre ... 
- 《CheckboxDemo.java》
			import java.awt.*; import java.applet.Applet; public class CheckboxDemo extends Applet { String Uni[ ... 
- (转)Ratchet教程:Buttons组件
			原文:http://www.w3cplus.com/mobile/create-buttons-with-ratchet.html Ratchet教程:Buttons组件 ... 
- (转)JS中innerHTML,innerText,value
			原文:http://holysonll.blog.163.com/blog/static/21413909320134111054352/ JS中innerHTML,innerText,value 2 ... 
- java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
			java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer) 
