Q:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without
repeating letters for "abcabcbb" is "abc", which the length is 3....
分类:
其他好文 时间:
2015-02-01 19:13:07
阅读次数:
163
求解回文字符串:这道题是查找资料才得到的解法。具体思路如下:比如对字符串abcba,做如下处理#a#b#c#b#a#,目的是消除偶数的回文。计算一点的回文长度时,根据保存的前端的最大回文长度和中心点,判断当前点应该是从0开始计算,还是可以根据利用以前的结果。主要就是这个思路。class Soluti...
分类:
其他好文 时间:
2015-02-01 13:27:48
阅读次数:
173
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'32: Longest Valid Parentheseshttps://oj.leetcode.com/problems/longest-valid-parentheses/Gi...
分类:
编程语言 时间:
2015-02-01 01:52:20
阅读次数:
319
链接:click here
题意:tip:最长公共子序列也称作最长公共子串(不要求连续),英文缩写为LCS(Longest Common Subsequence)。其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已知序列的最长公共子序列。
输入第一行给出一个整数N(0
接下来每组数据两行,分别为待测的两组字符串。每个字符串长度不大于...
分类:
其他好文 时间:
2015-01-31 23:19:56
阅读次数:
323
这题我的第一感觉就是用DFS。自己写的貌似不够完美,因为我看见别人的时间都特别的短,而我的有点长。
#include
#include
#include
#include
#include
#include
using namespace std;
const int N=102;
int height[N][N];
bool visited[N][N];
int dx[]={1,0,-1,0}...
分类:
其他好文 时间:
2015-01-31 21:53:26
阅读次数:
220
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest ...
分类:
其他好文 时间:
2015-01-31 15:56:51
阅读次数:
168
Write a function to find the longest common prefix string amongst an array of strings.即找出一组字符串的最长公共前缀。public class Solution { public String longest...
分类:
其他好文 时间:
2015-01-31 12:06:54
阅读次数:
110
题目链接:http://blog.csdn.net/u014361775/article/details/42873875题目解析:给定两行字符串序列,输出它们之间最大公共子单词的个数对于给的两个序列X 和 Y,用i 和 j分别作为它们的前缀指针,f[i][j]表示序列X的前缀Xi 和 序列Y的前缀...
分类:
其他好文 时间:
2015-01-30 19:12:19
阅读次数:
428
原题地址最初的想法是用动态规划,令palin[i][j]表示s[i..j]是否是回文串,则有递推公式palin[i][j] = s[i] == s[j] && palin[i+1][j-1]。因为递推式只使用相邻层的值,所以编码的时候可以将二维状态数组压缩成一维的。代码: 1 string long...
分类:
其他好文 时间:
2015-01-30 17:03:05
阅读次数:
105
题目:Write a function to find the longest common prefix string amongst an array of strings.
找出所有字符串的最长公共前缀。这道题很简单,但需要注意减少比较字符的操作次数。
2个字符串的最长公共前缀,其长度肯定不会超过最短的字符串的长度,设最短的字符串长度为n,那么只要比较这2个字符串的前n个...
分类:
其他好文 时间:
2015-01-30 16:04:25
阅读次数:
122