这道题好理解,但是要自己想的话还是很难想出来的,动态规划说白了就是记录当前的结果,留给后面的用。求最长合法匹配的长度,这道题可以用一维动态规划逆向求解。假设输入括号表达式为String s,维护一个长度为s.length的一维数组dp[],数组元素初始化为0。 dp[i]表示从s[i]到s[s.le...
分类:
其他好文 时间:
2015-07-01 15:45:27
阅读次数:
124
题目:LeetCode 005 Longest Palindromic SubstringGiven a string S, find the longest palindromic substring in S. You may assume that the maximum length of ...
分类:
其他好文 时间:
2015-06-30 14:49:25
阅读次数:
108
Write a function to find the longest common prefix string amongst an array of strings.
我的解决方案:
class Solution {
public:
string longestCommonPrefix(vector& strs)
{...
分类:
其他好文 时间:
2015-06-30 00:07:21
阅读次数:
144
1 class Solution { 2 public: 3 /** 4 * @param strs: A list of strings 5 * @return: The longest common prefix 6 */ 7 string...
分类:
其他好文 时间:
2015-06-29 16:36:19
阅读次数:
197
Write a function to find the longest common prefix string amongst an array of strings.直接按第一个元素开始比较,最后截取符合要求的前段。var longestCommonPrefix = function(strs...
分类:
其他好文 时间:
2015-06-29 11:32:33
阅读次数:
82
题意很简单,就是寻找一个字符串中连续的最长包含不同字母的子串。其实用最朴素的方法,从当前字符开始寻找,找到以当前字符开头的最长子串。这个方法猛一看是个n方的算法,但是要注意到由于字符数目的限制,其实这是个O(Cn)的算法,最长也不过是C长度。所以我觉得普通方法应该是能过的。于是写了一个,字符数目最大...
分类:
其他好文 时间:
2015-06-29 00:23:08
阅读次数:
107
1 class Solution { 2 public: 3 /** 4 * @param A, B: Two strings. 5 * @return: The length of longest common subsequence of A and B. 6 ...
分类:
其他好文 时间:
2015-06-28 17:04:49
阅读次数:
107
1 class Solution { 2 public: 3 /** 4 * @param A, B: Two string. 5 * @return: the length of the longest common substring. 6 */ ...
分类:
其他好文 时间:
2015-06-28 17:00:49
阅读次数:
94
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le...
分类:
其他好文 时间:
2015-06-27 06:24:03
阅读次数:
127
题意:给多个字符串,返回这些字符串的最长公共前缀。思路:直接逐个统计同一个位置上的字符有多少种,如果只有1种,那么就是该位是相同的,进入下一位比较。否则终止比较,返回前缀。可能有一个字符串会比较短,所以前缀最长也只是最短字符串的长度。 1 class Solution { 2 public: 3 ....
分类:
其他好文 时间:
2015-06-27 01:16:45
阅读次数:
268