LeetCode: 5. Longest Palindromic Substring

class Solution {
public:
//动态规划算法
string longestPalindrome(string s) {
int n = s.length();
int longestBegin = 0;
int maxLen = 1;
bool table[1000][1000] = {false};
for (int i = 0; i < n; i++) {
table[i][i] = true;
}//对角设为1
for (int i = 0; i < n-1; i++) {
if (s[i] == s[i+1]) {
table[i][i+1] = true;
start = i;
maxLen = 2;
}
}//检查是否存在"aa"这样的 for (int len = 3; len <= n; len++) {
for (int i = 0; i < n-len+1; i++) {
int j = i+len-1;
if (s[i] == s[j] && table[i+1][j-1]) {
table[i][j] = true;
start = i;
maxLen = len;
}
}
}
return s.substr(start, maxLen);
}
};

[LeetCode_5] Longest Palindromic Substring的更多相关文章

  1. 最长回文子串-LeetCode 5 Longest Palindromic Substring

    题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  2. leetcode--5. Longest Palindromic Substring

    题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...

  3. [LeetCode] Longest Palindromic Substring 最长回文串

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  4. No.005:Longest Palindromic Substring

    问题: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  5. Leetcode Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  6. 【leedcode】 Longest Palindromic Substring

    Given a , and there exists one unique longest palindromic substring. https://leetcode.com/problems/l ...

  7. 5. Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  8. leetcode-【中等题】5. Longest Palindromic Substring

    题目 Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...

  9. Leetcode5:Longest Palindromic Substring@Python

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

随机推荐

  1. HTML JQuery 技巧总结

    元素之间的操作 $(".level1").children()  获取到所有相邻的子元素$(".level1").children("a") ...

  2. C#注解属性的感想一:

    C#当中Attribute(中文注解属性)已经知道这个概念已经很久很久了,不过悲剧的是在实际项目当中重来没有用它来做过什么东西,以致对它的理解总是很浅薄,更谈不上如何在实际项目中运用它.最近在学习&l ...

  3. Windows7+VirtualBox+Ubuntu本地开发环境搭建

    首先下载相应的VirtualBox和Ubuntu镜像文件 安装Ubuntu操作系统 一 网络设置 将虚拟机的network连接模式设置为Bridge模式,注意无线网卡要与本机的无线网卡名称一致 在wi ...

  4. charles抓包工具的中文乱码解决方法

    charles是 MAC上最好用的抓包工具.charles 网上的参考文档已经很多,我就不再赘述啦.只是说说我在安装过程遇到的问题和解决方法,仅供参考. charles抓包的数据中的中文内容显示乱码, ...

  5. Css定位之relative_慕课网课程笔记

    前言 最近在慕课网上跟着张鑫旭大神重新学习一遍CSS相关的知识,以下是学习的笔记以及个人一些理解 relative对绝对定位的限制 1.限制绝对定位 绝对定位的top.left.right和botto ...

  6. C# 连接Oracle ,免安装客户端

    在.NET平台下开发Oracle应用的小伙伴们肯定都知道一方面做Oracle开发和实施相比SqlServer要安装Oracle客户端(XCopy.自己提取相关文件也有一定复杂性),另一方面相比JAVA ...

  7. 理工科应该的知道的C/C++数学计算库(转)

    理工科应该的知道的C/C++数学计算库(转) 作为理工科学生,想必有限元分析.数值计算.三维建模.信号处理.性能分析.仿真分析...这些或多或少与我们常用的软件息息相关,假如有一天你只需要这些大型软件 ...

  8. poj 2376 Cleaning Shifts

    http://poj.org/problem?id=2376 Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  9. (转)如何学习Java技术?谈Java学习之路

    51CTO编者注:这篇文章已经是有数年“网龄”的老文,不过在今天看来仍然经典.如何学习Java?本篇文章可以说也是面对编程初学者的一篇指导文章,其中对于如何学习Java的步骤的介绍,很多也适用于开发领 ...

  10. C++之路进阶——codevs2306(晨跑)

    2306 晨跑 2009年省队选拔赛山东  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master       题目描述 Description Elaxia最近迷恋 ...