leetcode 132 Palindrome Pairs 2
lc132 Palindrome Pairs 2

大致与lc131相同,这里要求的是最小分割方案
同样可以分割成子问题
dp[i][j]还是表示s(i~j)是否为palindrome
res[i]则用来记录s(0~i)的最小cut数
class Solution {
public int minCut(String s) {
int[] dp = new int[s.length()];
boolean[][] isP = new boolean[s.length()][s.length()];
for(int i=0; i<s.length(); i++){
int min = i;
for(int j=0; j<=i; j++){
if(s.charAt(i) == s.charAt(j) && (i-j <= 1 || isP[j+1][i-1])){
isP[j][i] = true;
min = j==0 ? 0 : Math.min(min, dp[j-1]+1);
}
}
dp[i] = min;
}
return dp[s.length() - 1];
}
}
leetcode 132 Palindrome Pairs 2的更多相关文章
- LeetCode 336. Palindrome Pairs
原题链接在这里:https://leetcode.com/problems/palindrome-pairs/ 题目: Given a list of unique words, find all p ...
- leetcode 131 Palindrome Pairs
lc131 Palindrome Pairs 解法1: 递归 观察题目,要求,将原字符串拆成若干子串,且这些子串本身都为Palindrome 那么挑选cut的位置就很有意思,后一次cut可以建立在前一 ...
- leetcode@ [336] Palindrome Pairs (HashMap)
https://leetcode.com/problems/palindrome-pairs/ Given a list of unique words. Find all pairs of dist ...
- 【LeetCode】Palindrome Pairs(336)
1. Description Given a list of unique words. Find all pairs of distinct indices (i, j) in the given ...
- leetcode 132. Palindrome Partitioning II ----- java
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [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 ...
- 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/132] Palindrome Partitioning & Palindrome Partitioning II
https://leetcode.com/problems/palindrome-partitioning/ Given a string s, partition s such that every ...
随机推荐
- C++之引用与符号“&”
一.&的意思: 1.取地址符,这时候它用于数据的前面,比如int a=&b; 2.C++里还使用&作为引用符,如果你确认程序是标准的C而非C++的话,那么可以排除是引用了.引用 ...
- iOS开发inputView和inputAccessoryView
1.简介 起初看到这两个属性是在UIResponder中,只是可读的: @property (nullable, nonatomic, readonly, strong) __kindof UIVie ...
- 得益于AI,这五个行业岗位需求将呈现显著增长趋势
得益于AI,这五个行业岗位需求将呈现显著增长趋势 人工智能与人类工作是当下许多人津津乐道的一个话题,而讨论的重点大多是围绕在"未来人工智能会不会抢走我们的工作"这个方面.本文作者 ...
- JVM内核-原理、诊断与优化学习笔记(九):锁
文章目录 线程安全 多线程网站统计访问人数 多线程访问ArrayList 对象头Mark Mark Word,对象头的标记,32位 描述对象的hash.锁信息,垃圾回收标记,年龄 偏向锁 轻量级锁 B ...
- nginx分布式实例入门操作
本文目的 前段时间学习WCF已经渐入佳境,完成了既定学习目标,转入分布式系统学习.本文技术路线是: 采用wcf实现分布式服务端和客户端,客户端部署于本地主机,nginx和WCF部署于虚拟机端(分别是三 ...
- Codeforces 166B - Polygon (判断凸包位置关系)
Codeforces Round #113 (Div. 2) 题目链接:Polygons You've got another geometrical task. You are given two ...
- Phpthink入门基础大全(CURD部分)
[ad code=1 align=center] $data[1]['name'] = ‘阳光雨' $data[1]['email'] = 'sccscc@vip.qq.com' $User>a ...
- 《DSP using MATLAB》Problem 8.45
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 如何用Maven创建web项目(具体步骤)转载
使用eclipse插件创建一个web project 首先创建一个Maven的Project如下图 本文转载于(http://blog.csdn.net/chuyuqing/article/detai ...
- scala 常用模式匹配类型
模式匹配的类型 包括: 常量模式 变量模式 构造器模式 序列模式 元组模式 变量绑定模式等. 常量模式匹配 常量模式匹配,就是在模式匹配中匹配常量 objectConstantPattern{ def ...