原题如下: Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique ...
分类:
其他好文 时间:
2016-08-15 18:59:55
阅读次数:
146
https://leetcode.com/problems/longest-palindromic-substring/ 题目:求字符串最长回文串。 第一种思路:以每一个字符为回文串中间的字符时,最长的回文串。考虑回文串字符个数为奇数,偶数的2种情况。 x--,j++ 的向两边扩展,判断最长的回文串 ...
分类:
其他好文 时间:
2016-08-13 21:08:35
阅读次数:
113
这道题的关键点在于,对于字符串的赋值操作要谨慎,尽量采用记录下标的方式,而不是整个字符串的赋值,这样可以节省时间。 ...
分类:
其他好文 时间:
2016-08-09 18:51:00
阅读次数:
149
这道题是比较常考的题目,求回文子串,一般有两种方法。 第一种方法比较直接,实现起来比较容易理解。基本思路是对于每个子串的中心(可以是一个字符,或者是两个字符的间隙,比如串abc,中心可以是a,b,c,或者是ab的间隙,bc的间隙)往两边同时进行扫描,直到不是回文串为止。假设字符串的长度为n,那么中心 ...
分类:
其他好文 时间:
2016-07-21 00:35:38
阅读次数:
152
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longes ...
分类:
其他好文 时间:
2016-07-15 00:03:09
阅读次数:
113
string s = "这里放十六进制字符串"; byte[]buff=new byte[s.Length/2]; int index=0; for (int i = 0; i < s.Length; i += 2) { buff[index] = Convert.ToByte(s.Substrin ...
DP。。 f[i][j][k]表示左上结束节点是第i条副对角线上的第j个点,右下结束节点是第n*2-i条副对角线上的第k个点,构成回文的方案数。 i那维滚动一下。时间复杂度O(n^3)空间复杂度O(n^2) 1 #include<cstdio> 2 #include<iostream> 3 #inc ...
分类:
其他好文 时间:
2016-07-05 22:09:35
阅读次数:
172
解决方法:直接简单粗暴写两个.有点挫,但实现需求了. <font style="color:red" ng-show="boxlist.lineTitle.length > 9">{{ boxlist.lineTitle.length > 9 ? boxlist.lineTitle.substrin ...
分类:
其他好文 时间:
2016-07-01 18:20:07
阅读次数:
257
最长回文子串 可以采用DP法,遍历法以及manacher算法 目前自己只实现了遍历法,因为比较直观而且简单- -,之后再完善。 个人感觉此问题可以作为学习动态规划的题目,目前还在学习动态规划中,处于能理解能看懂,但是还不能将动态规划作为解题工具的状态,需要理解更深刻。 遍历法: 简单来说就是遍历字符 ...
分类:
其他好文 时间:
2016-06-30 16:13:06
阅读次数:
112