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", Return1since the palindrome partitioning["aa","b"]could be produced using 1 cut.

C++

class Solution {
public:
int minCut(string s) {
int n = s.size();
if(n < 2) return 0;
vector<int> dp(n, INT_MAX);
vector<bool> tmp(n, false);
vector<vector<bool> > p(n, tmp);
for(int i=0; i<n; i++){
for(int j=i; j>-1; j--){
if(s[i] == s[j] && (i-j < 2 || p[j+1][i-1])){
p[j][i] = true;
dp[i] = min(dp[i], j == 0? 0 : dp[j-1] + 1);
}
}
}
return dp.back();
}
};

palindrome-partitioning-ii leetcode C++的更多相关文章

  1. Palindrome Partitioning II Leetcode

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

  2. Palindrome Partitioning II Leetcode java

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

  3. LeetCode:Palindrome Partitioning,Palindrome Partitioning II

    LeetCode:Palindrome Partitioning 题目如下:(把一个字符串划分成几个回文子串,枚举所有可能的划分) Given a string s, partition s such ...

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

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

  5. [LeetCode] Palindrome Partitioning II 解题笔记

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

  6. 【leetcode】Palindrome Partitioning II

    Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...

  7. leetcode 131. Palindrome Partitioning 、132. Palindrome Partitioning II

    131. Palindrome Partitioning substr使用的是坐标值,不使用.begin()..end()这种迭代器 使用dfs,类似于subsets的题,每次判断要不要加入这个数 s ...

  8. LeetCode: Palindrome Partitioning II 解题报告

    Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...

  9. 【LeetCode】132. Palindrome Partitioning II

    Palindrome Partitioning II  Given a string s, partition s such that every substring of the partition ...

  10. 19. Palindrome Partitioning && Palindrome Partitioning II (回文分割)

    Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...

随机推荐

  1. CPU到底是什么东西?它为什么能够执行数学运算?

    CPU到底是什么东西?它为什么能够执行数学运算? 本文地址http://yangjianyong.cn/?p=20转载无需经过作者本人授权 简单的物理电路 先来看一张初中学过的物理电路图: 从图中我们 ...

  2. 手把手教你调试SpringBoot启动 IoC容器初始化源码,spring如何解决循环依赖

    授人以鱼不如授人以渔,首先声明这篇文章并没有过多的总结和结论,主要内容是教大家如何一步一步自己手动debug调试源码,然后总结spring如何解决的循环依赖,最后,操作很简单,有手就行. 本次调试 是 ...

  3. Linux系列(11) - PATH环境变量

    前言 在Liunx当中要想执行"执行脚本"."执行文件"或者"执行命令",需要用绝对路径:因此环境变量就出来了,将路径放到环境变量中,环境变 ...

  4. gin 源码阅读(1) - gin 与 net/http 的关系

    gin 是目前 Go 里面使用最广泛的框架之一了,弄清楚 gin 框架的原理,有助于我们更好的使用 gin. 这个系列 gin 源码阅读会逐步讲明白 gin 的原理. gin 概览 想弄清楚 gin, ...

  5. win10系统git的安装与使用命令

    一.git简介 git是一个开源的分布式版本控制系统,可以高效的进行项目版本管理.分布式相比集中式最大的区别在于:分布式开发者可以提交到本地,每个开发者通过克隆在本地机器上拷贝一个完整的git仓库. ...

  6. 发送curl请求的函数

    //发送curl请求的函数function curl_request($url, $post = false, $data=array(), $https = false){ //使用curl_ini ...

  7. Python+selenium自动化生成测试报告

    批量执行完用例后,生成的测试报告是文本形式的,不够直观,为了更好的展示测试报告,最好是生成HTML格式的. unittest里面是不能生成html格式报告的,需要导入一个第三方的模块:HTMLTest ...

  8. JavaEE & Tomcat 介绍

    目录 企业开发介绍 JavaEE 规范 Web 概述 系统结构简介 C/S 结构 B/S 结构 两种结构的区别及优略 Tomcat Tomcat 介绍 关于服务器 Tomcat下载与安装 Tomcat ...

  9. Go语言之结构体与方法

    一.结构体 结构体是一系列属性的集合(类似于 Python 中的类) 1.结构体的定义与使用 // 定义 type Person struct { Name string Age int Sex st ...

  10. C++学习 2 指针

    指针:指针保存的是数据的地址: #include<iostream> using namespace std; int main() { //1.定义指针 int a = 10; //指针 ...