题目: Design and implement a data structure for Least
Recently Used (LRU) cache. It should support the following operations:getandset.
get(key)- Get ...
分类:
其他好文 时间:
2014-05-16 05:42:29
阅读次数:
280
题目: Given a linked list, determine if it has a
cycle in it. Follow up: Can you solve it without using extra space?解题思路:
使用快慢指针,快指针每次走两步,慢指针每次走一步...
分类:
其他好文 时间:
2014-05-16 05:19:21
阅读次数:
271
题目: Given a linked list, return the node where the
cycle begins. If there is no cycle, returnnull. Follow up: Can you solve it
without using extr...
分类:
其他好文 时间:
2014-05-16 04:50:13
阅读次数:
329
本文分别用非递归和递归两种方式实现了链表的反转,在九度OJ上测试了非递归版本,AC。
题目描述:
输入一个链表,反转链表后,输出链表的所有元素。
(hint : 请务必使用链表)
输入:
输入可能包含多个测试样例,输入以EOF结束。
对于每个测试案例,输入的第一行为一个整数n(0<=n<=1000):代表将要输入的链表的个数。
输入的第二行包含n个整数t(0<=t<=1000000):代表链表元素。
输出:
对应每个测试案例,
以此输出链表反转后的元素,如没有元素则输出NULL。
样例输入:...
分类:
其他好文 时间:
2014-05-15 06:41:12
阅读次数:
315
OJ题目:click here~~
题目分析:设dp[ i ] 为前i个数的子序列的个数 , 下标从1开始。计算dp[ i ] 。第一种情况, 如果x[ i ] 与前面的数都不相同 , 则
dp[ i ] = dp[ i - 1] + dp[ i - 1] + 1 , 即 = 都把x[ i ] 放在后面 + 都不把x[ i ]放在后面 + x[ i ] 单独成一个序列。
第二种情况,如果x[...
分类:
其他好文 时间:
2014-05-15 05:13:13
阅读次数:
223
1、
??
Populating Next Right Pointers in Each Node
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate...
分类:
其他好文 时间:
2014-05-15 04:57:36
阅读次数:
221
九度OJ上AC,采用归并的思想递归实现。
题目描述:
输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。
(hint: 请务必使用链表。)
输入:
输入可能包含多个测试样例,输入以EOF结束。
对于每个测试案例,输入的第一行为两个整数n和m(0<=n<=1000, 0<=m<=1000):n代表将要输入的第一个链表的元素的个数,m代表将要输入的第二个链表的元素的个数。
下面一行包括n个数t(1<=t<=1000000):代表链表一中的元素。接下来一行包含m个元素,s...
分类:
其他好文 时间:
2014-05-15 03:18:31
阅读次数:
356
OJ升级,代码可能会丢失. 所以要事先备份. 一开始傻傻的复制粘贴, 后来实在不能忍, 得益于大潇的启发和聪神的原始代码, 网页爬虫走起!
已经有段时间没看Python, 这次网页爬虫的原始代码是 python2.7版本, 试了一下修改到3.0版本, 要做很多包的更替,感觉比较烦,所以索性就在这个2.7版本上完善了.
首先观赏一下原始代码,我给加了一些注释:
# -*-...
分类:
编程语言 时间:
2014-05-15 02:39:45
阅读次数:
439
OJ题目:click here~~
题目分析:n个[a b] 区间,对于i 属于[a b] ,从a开始,间隔c ,即i = a , i = a + c , i = a + 2*c …… 将x[ i ] 加1 ,x[ i ] 初值为0 。
已知最多只有一个x[ i ] 为奇数。找到这个i , 和这个奇数。
由于最多只有一个奇数,且奇数 + 偶数 = 奇数。用二分夹逼出这个奇数的位置。找到...
分类:
其他好文 时间:
2014-05-14 21:27:36
阅读次数:
176
1、
??
Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.
A subsequence of a string is a new string which is formed from the original str...
分类:
其他好文 时间:
2014-05-14 20:22:58
阅读次数:
275