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 ...
随机推荐
- Java 时间、日期类
1. System类 currentTimeMillis():返回当前时间的long型值.此long值是从1970年1月1日0点0分00秒开始到当前的毫秒数. 此方法常用来计算时间差. 2. Date ...
- Java 枚举&注解
枚举类 如何自定义枚举类 JDK1.5之前需要自定义枚举类 JDK 1.5 新增的 enum 关键字用于定义枚举类 若枚举只有一个成员, 则可以作为一种单例模式的实现方式 //枚举类 class Se ...
- 多线程同步内功心法——PV操作上(未完待续。。。)
阅读本篇之前推荐阅读以下姊妹篇: <秒杀多线程第四篇一个经典的多线程同步问题> <秒杀多线程第五篇经典线程同步关键段CS> <秒杀多线程第六篇经典线程同步事件Event& ...
- Android之sdcard操作
private static final String FILENAME = "abc.txt"; private static final String DIR = " ...
- Google search
filetype: active directory filetype: eg : lady gaga filetype:mp3 link: eg : link : supinfo.com(链接到su ...
- 实现IOS圆角风格的列表ListView
这段代码目前已经加在我的一个jar包androidkit中,还没发布. 适用于android1.6以上,不依赖其他jar包 使用时不需要继承这里的RoundListAdapter.只需要在你实现了Li ...
- SharePoint 2013 搜索体系结构
博客地址:http://blog.csdn.net/FoxDave 本文参考自微软官方的Chart,记录一下,算是自己对这部分知识的总结. Microsoft® SharePoint® Server ...
- python解无忧公主的数学时间097.py
python解无忧公主的数学时间097.py """ python解无忧公主的数学时间097.py codegay 2016年3月30日 00:17:26 http:// ...
- yeild
正在使用cpu的线程,退出,返回等待池,其他优先级相同的线程竞争上岗.
- HTML--10Jquery
在<网页制作Dreamweaver(悬浮动态分层导航)>中,运用到了jQuery的技术,轻松实现了菜单的下拉.显示.隐藏的效果,不必再用样式表一点点地修改,省去了很多麻烦,那么jQuery ...