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 ...
随机推荐
- ios 学习 广告图片轮播器
// // ViewController.m // 图片轮播器 // // Created by zjj on 15/5/23. // Copyright (c) 2015年 zjj. All rig ...
- 管理Fragment
转载原地址:http://blog.csdn.net/harvic880925/article/details/44927375 相关文章: 1.<Fragment详解之一——概述>2.& ...
- MySQL的高级查询
高级查询 1.连接查询(对列的扩展) 第一种形式select * from Info,Nation #会形成笛卡尔积 select * from Info,Nation where Info.Nati ...
- UVa 10318 Security Panel
题意:给你一个3*3的翻转模版,深色部分表示翻转,浅色部分不变.然后你可以在r*c的矩形里依照模版进行翻转,要求所有点亮所有块.输出最小的步骤. 思路:有一点比较好想.每个块至多被翻转一次,翻两次的效 ...
- 如何由Height Map生成Normal Map
转自:http://www.cnblogs.com/cxrs/archive/2009/11/01/1594155.html Nvidia和ATI都有相应的工具把Heightmap转成NormalMa ...
- Ogre骨骼动画
转自:http://blog.csdn.net/yanonsoftware/article/details/1281516 OGRE的基本动画控制是很简单的,设置一个动画的操作是这样: // Set ...
- JSP重定向传递参数
我一个JSP程序,要实现前台提交数据给后台处理后,后台jsp自动跳转到另一个jsp页面,这种方式也叫重定向,重定向的方法有多种,暂时我试过的并且能成功的有两个: 一种是用 response.sendR ...
- Intellij IDEA Help
https://www.jetbrains.com/idea/help/intellij-idea.html https://www.jetbrains.com/idea/help/creating- ...
- 通过一个Thinkphp完成多个项目
1.单独取压缩包中的Thinkphp文件夹 2.在单独的项目内创建一个引入文件 3.通过浏览器访问该index.php 会创建相应的目录
- ZOJ2006 (最小表示法)
var s:ansistring; cas:longint; function minp(st,len:longint):longint; var p1,p2,k,tmp:longint; begin ...