[Leetcode]Palindrome Partitioning II
来源:互联网 发布:苹果launchpad软件 编辑:程序博客网 时间:2024/06/04 01:15
class Solution {
public:
int minCut(string s) {
//int result=INT_MAX;
const int num=s.size();
bool pal[num][num];
int f[num+1];
for(int i=0;i<num;i++)
for(int j=0;j<num;j++)
pal[i][j]=false;//初始化,假设全部都没有回文
for(int i=0;i<=num;i++)
f[i]=num-i-1;//初始化,假设全部都没有回文,每个位置需要多少个分割点,从右到左变多
for(int i=num-1;i>=0;i--)
for(int j=i;j<num;j++)
{
if(s[i]==s[j]&&(j-i<2||pal[i+1][j-1]))//如果出现回文
{
pal[i][j]=true;
f[i]=min(f[i],f[j+1]+1);//从右到左遍历时,回文右边初始点的分割点数加1,和本身在之前更新过后需要的分割点
}
}
return f[0];
}
};
public:
int minCut(string s) {
//int result=INT_MAX;
const int num=s.size();
bool pal[num][num];
int f[num+1];
for(int i=0;i<num;i++)
for(int j=0;j<num;j++)
pal[i][j]=false;//初始化,假设全部都没有回文
for(int i=0;i<=num;i++)
f[i]=num-i-1;//初始化,假设全部都没有回文,每个位置需要多少个分割点,从右到左变多
for(int i=num-1;i>=0;i--)
for(int j=i;j<num;j++)
{
if(s[i]==s[j]&&(j-i<2||pal[i+1][j-1]))//如果出现回文
{
pal[i][j]=true;
f[i]=min(f[i],f[j+1]+1);//从右到左遍历时,回文右边初始点的分割点数加1,和本身在之前更新过后需要的分割点
}
}
return f[0];
}
};
0 0
- LeetCode : Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- leetcode:Palindrome Partitioning II
- 【leetcode】Palindrome Partitioning II
- leetcode - Palindrome Partitioning II
- [LeetCode]Palindrome Partitioning II
- [Leetcode]Palindrome Partitioning II
- [leetcode]Palindrome Partitioning II
- leetcode Palindrome Partitioning II
- LeetCode-Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- LeetCode - Palindrome Partitioning II
- [Leetcode]Palindrome Partitioning II
- 【leetcode】Palindrome Partitioning II
- LeetCode Palindrome Partitioning II
- [leetcode]Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning II
- xCode 4.2如何检测程序在真机中的内存占用
- 代码里打印程序所占用的内存
- 关于在ubantu输入类似node ,brunch, less等等命令失效
- Android Notification
- 输入两个整数n和m,从数列1,2,3,……n中随意取几个数,使其和等于m。要求将所有的可能组合列出来。实际上就是一个背包问题
- [Leetcode]Palindrome Partitioning II
- 输入一个表示整数的字符串,把该字符串转换成整数并输出。
- Android下视频通信
- ubuntu 安装jdk
- 寒城攻略:Listo 教你Linux Cent OS 服务器从搭建到配置
- Java安全通信:HTTPS与SSL
- kdump几种存储方式实现
- 每位Web开发者都应知道的HTTPS是如何保证连接安全
- LeetCode2.2.2 @ Reverse Linked List II 反转链表II D3F2