Palindrome Partitioning II Leetcode
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.
给定一个字符串s,将s分割成一些子串,使每个子串都是回文。
比如,给出字符串s = "aab",
返回 1, 因为进行一次分割可以将字符串s分割成["aa","b"]这样两个回文子串
public class Solution {
public int minCut(String s) {
int n = s.length();
int[] cuts = new int[n];
boolean[][] dp = new boolean[n][n]; for (int i = 0; i < n; i++) {
cuts[i] = i;
for (int j = 0; j <= i; j++) {
if (s.charAt(i) == s.charAt(j) && (i - j <= 1 || dp[j + 1][i - 1])) {
dp[j][i] = true; if (j > 0) {
cuts[i] = Math.min(cuts[i], cuts[j - 1] + 1);
} else {
cuts[i] = 0;
}
} }
}
return cuts[n -1];
}
}
Palindrome Partitioning II Leetcode的更多相关文章
- Palindrome Partitioning II Leetcode java
题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...
- LeetCode:Palindrome Partitioning,Palindrome Partitioning II
LeetCode:Palindrome Partitioning 题目如下:(把一个字符串划分成几个回文子串,枚举所有可能的划分) Given a string s, partition s such ...
- leetcode@ [131/132] Palindrome Partitioning & Palindrome Partitioning II
https://leetcode.com/problems/palindrome-partitioning/ Given a string s, partition s such that every ...
- [LeetCode] Palindrome Partitioning II 解题笔记
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 【leetcode】Palindrome Partitioning II
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- leetcode 131. Palindrome Partitioning 、132. Palindrome Partitioning II
131. Palindrome Partitioning substr使用的是坐标值,不使用.begin()..end()这种迭代器 使用dfs,类似于subsets的题,每次判断要不要加入这个数 s ...
- LeetCode: Palindrome Partitioning II 解题报告
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- 【LeetCode】132. Palindrome Partitioning II
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- 19. Palindrome Partitioning && Palindrome Partitioning II (回文分割)
Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...
随机推荐
- sql between and
sql中的 a between 'a' and 'b' 基本上是代表 'a'>=a and 'b'<=a
- jquery的$.extend()、$.fn和$.fn.extend()
一种是类级别的插件开发,即给jquery添加新的全局函数,相当于给jquery类本身添加方法.如$.ajax()等,这就是用$.extend()实现 jquery的全局函数就是属于jquery命名空间 ...
- PHPCMS修改管理栏目下的模版设置的注意
要确保文件名后缀的统一才能被后台所找到 首页的必须是index开头.html结尾栏目首页的模板必须category开头.html结尾 -------例如导航栏上面的栏目页面 列表页的模板必须list开 ...
- 电脑中的Bois是什么
电脑中的Bois是什么 BOIS= Basic Input/Output System,基本输入输出系统,全称是ROM-BOIS,是只读存储器基本输入/输出系统的简写,它实际是一组被固化到电脑中,为电 ...
- css让图片作为按钮的背景并且大小合适
最近在做ASP大作业,在做html页面的时候想把一个图片作为按钮的背景,搞了好久终于在csdn上找到了满意的答案: background-size: cover; 只需要这一句就ok了,就是这么简答. ...
- JavaScript学习笔记——DOM_document对象
javascript-document对象详解 DOM document(html xml) object modledocument对象(DOM核心对象) 作用: 1.内容 innerHTML 2. ...
- 对二进制加密(分散保存-s=sy+a+b)
#include <stdio.h> #define L 40 void jiaM(int * s,int * a,int *b,int *sy); void jieM(int * a,i ...
- C#--中实现邮件发送
MailMessage mailmessage = new MailMessage(); mailmessage.To.Add("接受邮箱");//可以添加多个接收邮箱 mailm ...
- Bitmap动画
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html htt ...
- 免费api大全
天气接口 气象局接口 完整数据:http://m.weather.com.cn/data/101010100.html 解析 用例 当天数据:http://www.weather.com.cn/dat ...