Given a binary tree, findits maximum depth.
The maximum depth is thenumber of nodes along the longest path from the root node down to the farthestleaf node.
可用递归,效率低。
这里用类似层次遍历的算法。设置一个队列和两个int变量...
分类:
其他好文 时间:
2015-01-30 09:10:56
阅读次数:
261
题目链接:Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.
这道题的要求是在字符串数组中找到最长公共前缀。
思路比较简单,就是两个字符串逐个比较,找最长公共子串。这里采用将每个字符串都与第一个字符串相比较,求最长子串。
时间...
分类:
其他好文 时间:
2015-01-29 21:13:30
阅读次数:
197
原题地址双指针法。右指针不断向右试探,当遇到重复字符时停下来,此时左指针开始向右收缩,直到去掉那个重复字符。代码: 1 int lengthOfLongestSubstring(string s) { 2 map record; 3 int maxLen = 0; 4...
分类:
其他好文 时间:
2015-01-29 19:20:25
阅读次数:
140
Total Accepted: 1167
Total Submissions: 3961
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.
For example,Given s = “eceba”,
T is...
分类:
其他好文 时间:
2015-01-28 06:15:59
阅读次数:
149
Longest Valid Parentheses.
分类:
其他好文 时间:
2015-01-28 00:43:26
阅读次数:
202
题目链接:Longest Palindromic Substring
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 longest palindromic ...
分类:
其他好文 时间:
2015-01-27 23:35:02
阅读次数:
144
题目链接:Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters...
分类:
其他好文 时间:
2015-01-27 23:33:44
阅读次数:
176
描述:
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 ...
分类:
其他好文 时间:
2015-01-27 20:21:40
阅读次数:
149
描述:
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 longest palindromic substring.
思路:
刚开始非常天...
分类:
其他好文 时间:
2015-01-27 20:21:30
阅读次数:
205
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 longest palindromic substring.(最长回文子串)
中心扩展法:
pub...
分类:
其他好文 时间:
2015-01-27 18:31:08
阅读次数:
151