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的更多相关文章

  1. LeetCode 336. Palindrome Pairs

    原题链接在这里:https://leetcode.com/problems/palindrome-pairs/ 题目: Given a list of unique words, find all p ...

  2. leetcode 131 Palindrome Pairs

    lc131 Palindrome Pairs 解法1: 递归 观察题目,要求,将原字符串拆成若干子串,且这些子串本身都为Palindrome 那么挑选cut的位置就很有意思,后一次cut可以建立在前一 ...

  3. leetcode@ [336] Palindrome Pairs (HashMap)

    https://leetcode.com/problems/palindrome-pairs/ Given a list of unique words. Find all pairs of dist ...

  4. 【LeetCode】Palindrome Pairs(336)

    1. Description Given a list of unique words. Find all pairs of distinct indices (i, j) in the given ...

  5. leetcode 132. Palindrome Partitioning II ----- java

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  6. [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 ...

  7. 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 ...

  8. Leetcode 132. Palindrome Partitioning II

    求次数的问题一般用DP class Solution(object): def minCut(self, s): """ :type s: str :rtype: int ...

  9. leetcode@ [131/132] Palindrome Partitioning & Palindrome Partitioning II

    https://leetcode.com/problems/palindrome-partitioning/ Given a string s, partition s such that every ...

随机推荐

  1. mysql 导出导入数据 -csv

    MySql数据库导出csv文件命令: mysql> select first_name,last_name,email from account into outfile 'e://output ...

  2. Java--下大雪模拟

    package firstpack; import java.awt.*; public class MyStar { public static void main(String[] args) { ...

  3. ionic-CSS:ionic 按钮

    ylbtech-ionic-CSS:ionic 按钮 1.返回顶部 1. onic 按钮 按钮是移动app不可或缺的一部分,不同风格的app,需要的不同按钮的样式. 默认情况下,按钮显示样式为:dis ...

  4. Linux下使用Eclipse 远程调试

    1 开启端口 修改/apache-tomcat-7.0.40/bin/catalina.sh 在合适的位置(请自行判断,只要有JAVA_OPTS的设定前后即可)插入下面的设定:UI_DEBUG=&qu ...

  5. jquery操作html元素之( 尺寸)

    jQuery 提供多个处理尺寸的重要方法: width() height() innerWidth() innerHeight() outerWidth() outerHeight() jQuery ...

  6. ps-使用通道抠图为XX换背景

    第一步先载入图片 点击通道,复制蓝色通道 然后点击新的蓝色通道,图像-调整-曲线-改变输入输出, 然后用历史画笔全部填黑.  然后载入选区,复制.在图层中新建蒙版 黏贴,反向(CTRL+I)就可以了. ...

  7. Codeforces 479【E】div3

    题目链接:http://codeforces.com/problemset/problem/977/E 题意:就是给你相连边,让你求图内有几个环. 题解:我图论很差,一般都不太会做图论的题.QAQ看官 ...

  8. HttpWebRequest请求返回非200的时候 HttpWebResponse怎么接受返回错误提示

    当我们使用HttpWebRequest发送请求的时候如果服务器返回的不是200状态,那么请求代码肯定会异常,其实请求和返回并没有什么异常,只是.net内部就认定了 返回的不要是200 就是异常 那么我 ...

  9. 数据库MySQL--修改数据表

    创建数据库::create database 数据库名: 如果数据不存在则创建,存在不创建:Create database if not exists 数据库名 ; 删除数据库::drop datab ...

  10. js日常总结

    1.html如何引入css和js文件 css:<link rel="stylesheet" href="css/index1.css(这是我的文件的地址)" ...