leetcode144 longest-palindromic-substring
题目描述
输出
"abcba"
动态规划
class Solution {
public:
/**
*
* @param s string字符串
* @return string字符串
*/
string longestPalindrome(string str) {
// write code here
int n=str.length();
if (n==0) return "";
bool dp[n][n];
fill_n(&dp[0][0],n*n,false);
int left=0,right=0,maxLen=0;
for (int j=0;j<n;j++)
{
dp[j][j]=true;
for (int i=0;i<j;i++)
{
dp[i][j]=(str[i]==str[j] && (j-i<2 || dp[i+1][j-1]));
if (dp[i][j]&& (j-i+1>maxLen))
{
left=i;
right=j;
maxLen=j-i+1;
}
}
}
return str.substr(left,right-left+1);
}
};
leetcode144 longest-palindromic-substring的更多相关文章
- 最长回文子串-LeetCode 5 Longest Palindromic Substring
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...
- leetcode--5. Longest Palindromic Substring
题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...
- [LeetCode] Longest Palindromic Substring 最长回文串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- No.005:Longest Palindromic Substring
问题: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...
- Leetcode Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- 【leedcode】 Longest Palindromic Substring
Given a , and there exists one unique longest palindromic substring. https://leetcode.com/problems/l ...
- [LeetCode_5] Longest Palindromic Substring
LeetCode: 5. Longest Palindromic Substring class Solution { public: //动态规划算法 string longestPalindrom ...
- 5. Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- leetcode-【中等题】5. Longest Palindromic Substring
题目 Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...
- Leetcode5:Longest Palindromic Substring@Python
Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...
随机推荐
- Java 读取文件中的每一行,并为每一行插入特定的字符串
工具 1:Eclipse Java EE IDE for Web Developers. Version: Photon Release (4.8.0). Build id: 20180619-120 ...
- apt-get 安装软件时出现:“文件尺寸不符” 问题
报错信息 命中:1 http://packages.deepin.com/deepin panda InRelease 命中:2 http://linux.teamviewer.com/deb sta ...
- regsvr32 bypass windows defender 新思路
原文链接:blog 在对regsvr32的用法进行了解之后,对于Casey Smith的远程js脚本执行命令的思路很感兴趣. 命令语法如下: regsvr32 /s /n /u /i:http://1 ...
- springCloud微服务调用失败【CannotGetJdbcConnectionException: Failed to obtain JDBC Connection】
详情如下: 2019-07-28 10:56:18.229 ERROR 16212 --- [nio-8081-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet ...
- 网页添加 Live2D 看板娘
我是先参考别人的[点击跳转]博客来做的.不过我发现网上很多人都没有把一些细节写出来,用了别人那里下载的文件后里面的一些跳转链接就跳到他们的页面了.所以我这里写一写如何修改这些跳转链接吧. 1. ...
- swoole为什么不建议使用static和global
$http = new swoole_http_server("0.0.0.0", 9501); $http->on("request", functio ...
- 往with as中写入数据的方法
方法1:直接写入,使用union all,简单直观,但程序运行效率低,几百条就很慢了 with dw_wms_outbound_info_v100 as( select '10700001' as o ...
- 源代码 VS 汇编代码 VS 目标代码 VS 字节码 VS 机器码
1.源代码(source code) 源代码就是平时我们开发的代码:比如C.Java.Python.Shell...等 public class HelloWorld { public static ...
- ERP仓库管理的操作与设计--开源软件诞生20
赤龙ERP库房管理讲解--第20篇 用日志记录"开源软件"的诞生 [点亮星标]----祈盼着一个鼓励 博主开源地址: 码云:https://gitee.com/redragon/r ...
- maven项目导入并运行
idea导入maven工程流程 找到要导入的文件位置 打开导入 选择manve 一直next就好 选择jdk,选择自己的jdk--home就可以 点击finished 等待坐标导入,查看右侧maven ...