题目要求判断最长的回文,有两种思路可供选择。
思路一,从两头进行判断,定义两个指针start_index和end_index分别指向头部和尾部,首先固定start_index,让end_index从最后一个元素向前遍历,直到碰到start_index,其间对start_index到end_index的范围进行回文判断,回文判断的规则很简单,如果start和end指向的元素一样,回文长度length=2,然后start+1,end-1,继续比较,如果符合则继续+2,直到start<end不再满足,注意在这之中...
分类:
其他好文 时间:
2015-07-09 14:34:42
阅读次数:
89
题目:
Write a function to find the longest common prefix string amongst an array of strings.
题意:
写出一个函数,找到一组数组中的最长公共子串。
算法分析:
需要构建两重循环。第一层是最短子串的长度,另一层是遍历字符串数组中的每个成员。
brute force的想法,以第一个字符串为标准,对于...
分类:
编程语言 时间:
2015-07-09 13:17:56
阅读次数:
138
定义:串(或空字符串)是由0个或多个字符组成的有限序列。区分:空串:长度为0.空格串:有一个或多个空格组成的串。串中常用的操作:1:求串长StrLength(S)返回S的元素个数,称为串的长度。例:设S=”A;/DOCUMENT/MARY.DOC”;则strlen(s)=20.2:串的定位:subS...
分类:
其他好文 时间:
2015-07-08 22:31:57
阅读次数:
259
Longest Consecutive Sequence
分类:
其他好文 时间:
2015-07-08 22:15:54
阅读次数:
137
相比 HDOJ 的 fatmouse‘s speed 这道题只需要输出 最长子序列的长度#includeusing namespace std;#define Size 1000int main(){ int N1; int table[Size+1]; i...
分类:
其他好文 时间:
2015-07-08 22:07:17
阅读次数:
110
Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
For "(()", the longest valid par...
分类:
其他好文 时间:
2015-07-08 19:08:38
阅读次数:
115
Extract Method(110) 将两个类的相同部分提取成函数Inline Method(117) 内联函数Replace Temp with Query(120) 将临时变量替代为查询语句Replace Method With Method Object(135) 用方法对象替换方法Subs...
分类:
其他好文 时间:
2015-07-08 18:13:27
阅读次数:
127
想法很直接 复杂度O(mn)class Solution: # @param {string[]} strs # @return {string} def longestCommonPrefix(self, strs): n = len(strs) if...
分类:
其他好文 时间:
2015-07-08 08:14:36
阅读次数:
139
这道题一开始无从下手,想到找到用hashtable,这样查询没个数是否在List中只需要O(1)时间。以上是第一步, 接下来的想法就比较自然, 将每个数都当成可能的起始点进行测试。待测试的起始点为n,如果n-1在set中,则n必不为起始数字,可以continue优化运行时间代码中使用set来实现ha...
分类:
其他好文 时间:
2015-07-07 10:50:22
阅读次数:
120