[LeetCode_5] Longest Palindromic Substring
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;}//对角设为1for (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);}
};
转载于:https://www.cnblogs.com/guoyunzhe/p/5850465.html
[LeetCode_5] 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 l ...
- [LeetCode] Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- [LeetCode]Longest Palindromic Substring题解(动态规划)
Longest Palindromic Substring: Given a string s, find the longest palindromic substring in s. You ma ...
- leetcode-【中等题】5. Longest Palindromic Substring
题目 Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...
- LeetCode: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 lengt ...
- LeetCode Longest Palindromic Substring
原题链接在这里:https://leetcode.com/problems/longest-palindromic-substring/ 题目: Given a string s, find the ...
- [*leetcode 5] Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- Longest Palindromic Substring
今天做一道最长回文子串问题 Given a string s, find the longest palindromic substring in s. You may assume that the ...
最新文章
- [COCI2015]COCI
- Iframe中的SSRS报表中使用windows.open在新窗口中不能打开URL中的问题
- CSP 1.0 语言规范
- Pygame制作答题类游戏的实现
- 《白帽子讲web安全》读书笔记
- 【数据结构笔记05】堆栈及其顺序存储、链式存储
- 【BZOJ4025】二分图(可撤销并查集+线段树分治)
- 再议动态二维数组,通过一句表达式完成矩阵的转置
- 华为荣耀手机指令代码大全_华为手机指令代码大全
- ppt convert to html,powerpoint(ppt)
- SharePoint中CAML日期格式
- html在抽奖图片自动效果图,jQuery实现图片随机切换、抽奖功能(实例代码)
- 加油站踩踏式逃亡?电网成大赢家?时代抛弃你的时候,真的一声不吭
- 大厂Java岗春招必看:论一个面渣逆袭之路上必学得那些知识点
- Flink Table 和 DataStream 转换
- 博弈游戏之三大博弈---bashWythoffNimm
- simple_html_dom(入门实例)
- 计算器简单篇(项目篇)
- Metronic-全球销量第一的HTML管理后台模版
- 利用VBA快速整合多个excel文件
热门文章
- 三线城市PHP5000怎么样,一线城市五千退休金,二线四千,三线三千,是一样生活水平吗?...
- java urlencode 解码_java.net.URLEncode编码 与 URLDecode解码问题
- mybatis 动态传入表名 注解_mybatis动态sql(注解方式)
- python结束进程树_【python爬虫】线程进程
- 深度学习(21)神经网络与全连接层四: 输出方式
- 结巴分词关键词相似度_gensim和jieba分词进行主题分析,文本相似度
- Linux Ubuntu 修改Grub,添加删除启动项,初步辨析Grub文件。
- 信息竞赛进阶指南--搜索相关(模板)
- R语言blotter包及相关工具
- 央行允许银行倒闭破产,那么储户的存款怎么办?