其实做起来会感觉很简单,需要注意的是要考虑效率的问题,毕竟可能是很长的字符串数组,所以可以考虑选取所有字符串中最短的那个来首先进行比较,因为最长公共子串肯定不会大于其长度,这样避免了字符串之间长度差异很大造成的效率损失,然后每次比较之后最长公共子串的长度也永远不会大于最短的那个字符串,只会不变或相等,只要遍历字符串数组,挨个对比、更改最短公共字符串记录即可,code如下:...
分类:
其他好文 时间:
2014-06-11 06:58:55
阅读次数:
226
题目:Maximum Depth of Binary TreeGiven a binary tree,
find its maximum depth.The maximum depth is the number of nodes along the
longest path from the ro...
分类:
其他好文 时间:
2014-06-10 10:09:13
阅读次数:
237
戳我去解题Write a function to find the longest
common prefix string amongst an array of strings.class Solution {public: string
longestCommonPrefix(vecto...
分类:
其他好文 时间:
2014-06-10 08:29:55
阅读次数:
189
题目描述:
Write a function to find the longest common prefix string amongst an
array of strings.
很简单的一道题目,但是我写了两个不一样的版本,运行时间确实数倍之差。。贴代码如下:
版本1:
{CSDN:CODE:384511}
这个版本的运行时间为 44 ms...
分类:
其他好文 时间:
2014-06-10 08:18:58
阅读次数:
291
一次总结两道题,两道题目都比较基础Description:Write a function to
find the longest common prefix string amongst an array of strings.分析:
这道题目最重要的知道什么叫prefix前缀, 否则一不小心就做...
分类:
其他好文 时间:
2014-06-09 21:08:16
阅读次数:
224
ListView 的高度 必须要设置成一个明确的值 或者match_parent
不然就会调用多次getView方法
分类:
移动开发 时间:
2014-06-09 18:51:50
阅读次数:
253
import sysfrom PyQt4 import QtGuifrom PyQt4 import
QtCore#Icon继承了QtGui.QWidget这个类class Icon(QtGui.QWidget): def
__init__(self,parent=None): ...
分类:
其他好文 时间:
2014-06-09 15:10:52
阅读次数:
227
一、代码实现如下(主程序代码,其他include代码见各个功能函数中)responseMsg();//$wechatObj->valid();class
wechatCallbackapiTest{ public function valid() { $echoStr = ...
分类:
微信 时间:
2014-06-08 20:54:23
阅读次数:
704
树中除了根节点之外,每个节点都有且仅有一个父节点,为了记录树中节点与节点之间的父子关系,可以为每个节点增加一个parent域,用以记录该节点的父节点。 对于下图中的树: 可以用下表来存储: 由此可见,只要用一个节点数组来保存树中的每个节点,并让每个节点记录其父节点在数组中的索引即可。 Java实现代码...
分类:
编程语言 时间:
2014-06-08 03:42:18
阅读次数:
289
题目: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. For "bbbbb" the longest substring is "b", with the length...
分类:
其他好文 时间:
2014-06-08 03:06:52
阅读次数:
221