题目
Write a function to find the longest common prefix string amongst an array of strings.
原题链接
解题思想
给一个字符串数组,求这些字符串的最长公共前缀。
这个题应该是比较简单的,直接写代码,一次AC。解题思想是依次对数组中的字符串求最长公共前缀。
代码实现
class Sol...
分类:
其他好文 时间:
2014-06-20 12:25:09
阅读次数:
247
昨天做了leetcode里的 Longest Palindromic Substring ,一开始用动态规划O(N^2),不管怎么改都超时了。。。于是在大神的帮助下,找到了传说中的Manacher算法,居然能在O(n)内求出来,瞬间给跪了。
本屌认为,这个算法主要是充分的利用了以前的匹配的结果,来起到了降低时间复杂度的作用,这点跟KMP算是有点类似。在预处理时有个小技巧就是将第0,1为设...
分类:
其他好文 时间:
2014-06-20 12:15:22
阅读次数:
305
先上用来生成Tree的JSON数据 [ { "id": "Root", "name":
"资源目录" }, { "id": "PF", "name": "批发价格", "parent": "Root" }, { "id": "PF93",
"name": "93#", "parent": "
分类:
其他好文 时间:
2014-06-13 13:49:33
阅读次数:
442
1.window对象不要去掉
window.parent.location2.firefox和ie内置的对象确实不一样,你用jquery吧这个是跨浏览器的,只需要$("#yourID").parent()就直接可以得到了
很方便,而且jquery也比较小,只有几十k,现在浏览器这么多 不可能不用跨浏...
分类:
其他好文 时间:
2014-06-11 23:01:55
阅读次数:
311
Implement an algorithm to print all valid (
properly opened and closed) combinations of n-pairs of parentheses.思路:比如 n = 3,
((())) 就是一个valid combinati...
分类:
其他好文 时间:
2014-06-11 13:19:00
阅读次数:
306
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
The Sudoku board could be partially filled, where empty cells are filled with the character '.'.
A partially fille...
分类:
其他好文 时间:
2014-06-07 12:51:12
阅读次数:
225
最长回文字串,相信做过Palindrome Partitioning II 这个题的同学应该可以很快做出来。没错,这个题还可以使用动态规划方法得到一个时间复杂度为O(n^2)的解法,当然如果你想要更好的时间复杂度的算法也是有的。好的,我们先来看看时间复杂度为O(n^2)的算法。
代码实现--动态规划O(n^2)
相信如果你在网上看过了别人的算法,你会发现我的算法是最简洁的。哈哈,这个题需要注意的是如果你用惯了vector的话,你这里肯定会得到超时的提示...
...代码二--复杂度为O(n)的算法...
分类:
其他好文 时间:
2014-06-07 12:08:43
阅读次数:
224
原题地址:https://oj.leetcode.com/problems/valid-sudoku/题意:Determine
if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board
could b...
分类:
编程语言 时间:
2014-06-07 11:26:18
阅读次数:
296
jquery获取父元素方法比较多,比如parent(),parents(),closest()这些都能帮你实现查找父元素或节点,下面我们来一一讲解:先举个例子,jquery获取父节点jquery获取父元素我们的目的是通过
id 为 item1 的便签a取到 class 为 parent1 的ul元素...
分类:
其他好文 时间:
2014-06-07 06:52:15
阅读次数:
144
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...
分类:
其他好文 时间:
2014-06-05 14:10:38
阅读次数:
304