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. SEO实战宝典阅读笔记

    1. 对搜索引擎更友好 1.1 sitemap sitemap自动生成 https://www.xml-sitemaps.com 谷歌 sitemap.xml 百度 sitemap.html 1.2 ...

  2. Scala的trait

    一:说明 1.介绍 2.功能 二:具体解释功能 1.定义接口 2.定义方法 3.定义字段 4.定义抽象字段 5.混合trait

  3. Notification中使用Glide

    之前一直在琢磨Glide自定义使用中的一些经验:今天简单的分享下Notification中使用Glide去加载icon方法: 我们都知道使用android通知时,一般可能会有如下代码: Notific ...

  4. win7 WindowsImageBackup 无法识别

    控制面板\所有控制面板项\备份和还原

  5. json转bean对象

    一下为个人收藏,以便下次使用. 前端传的json格式为: [{"suppliercode":"gylhld_gycqlt3_gycqlt1","pro ...

  6. C# Extension Methods

    In C#, extension methods enable you to add methods to existing class without creating a new derived ...

  7. 简单的oracle分页语句

    SELECT * FROM ( SELECT rownum rn,te.* FROM (SELECT * FROM  tb_enterprise) te  WHERE rownum <= 10) ...

  8. ssh无密码通信设置

    ■单向登陆配置:1.在本地机器中的~/.ssh/目录下执行下命令#ssh-keygen -t dsa然后全部回车,采用默认值.生成了一对密钥,id_dsa和id_dsa.pub,存放在用户目录的~/. ...

  9. kibana 使用

    统计IP前五的数据 统计相应时间 状态码统计 统计IP地图

  10. javascript数据结构和算法

    一.栈 javascript实现栈的数据结构(借助javascript数组原生的方法即可) //使用javascript来实现栈的数据结构 var Stack={ //不需要外界传参进行初始化,完全可 ...