OJ题目 :
click here~~
题目分析:给一个数字三角形,从最上面一个数字开始,方向只能往左下或者右下,一直到最后一行,求经过的所有数字和的最大值。
搞清楚在输入的数据中,route的方向就行。
AC_CODE
int num[102][102];
int main(){
int n , i , j , k ;
while(cin >> n){
...
分类:
其他好文 时间:
2014-07-22 23:05:55
阅读次数:
372
原题链接: http://oj.leetcode.com/problems/4sum/
这道题要求跟3Sum差不多,只是需求扩展到四个的数字的和了。我们还是可以按照3Sum中的解法,只是在外面套一层循环,相当于求n次3Sum。我们知道3Sum的时间复杂度是O(n^2),所以如果这样解的总时间复杂度是O(n^3)。代码如下:public ArrayList> fourSum(int[] num,...
分类:
其他好文 时间:
2014-07-22 23:01:34
阅读次数:
328
Problem A: Random PermutationsTime Limit: 1
SecMemory Limit: 128 MB Submit: 91Solved: 54Description随机排列生成算法
(运行a.exe输出数字的个数,运行a.exe test时输出为一次随机的排列)In...
分类:
其他好文 时间:
2014-05-05 23:03:04
阅读次数:
341
# Definition for a binary tree node# class
TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right
...
分类:
其他好文 时间:
2014-05-05 22:56:23
阅读次数:
419
Problem
Link:http://oj.leetcode.com/problems/longest-consecutive-sequence/This problem
is a classical problem where we can reduce the running time by ...
分类:
其他好文 时间:
2014-05-05 22:55:22
阅读次数:
552
Link:http://oj.leetcode.com/problems/reverse-nodes-in-k-group/Given a linked
list, reverse the nodes of a linked listkat a time and return its modifie...
分类:
其他好文 时间:
2014-05-05 22:46:42
阅读次数:
456
Link:http://oj.leetcode.com/problems/reverse-linked-list-ii/Reverse a linked
list from positionmton. Do it in-place and in one-pass.For example:Given1...
分类:
其他好文 时间:
2014-05-05 22:46:11
阅读次数:
411
Link:http://oj.leetcode.com/problems/swap-nodes-in-pairs/Given a linked list,
swap every two adjacent nodes and return its head.For example,Given1->2-...
分类:
其他好文 时间:
2014-05-05 22:45:37
阅读次数:
331
Problem
Link:http://oj.leetcode.com/problems/word-ladder/Two typical techniques are
inspected in this problem:Hash Table. One hash set is the words di...
分类:
其他好文 时间:
2014-05-05 22:44:44
阅读次数:
393
OJ题目:click here~~
题目分析:四柱汉诺塔。由于题目已经给出了求解方法,直接写代码即可。下面总结一下,四塔问题。
感谢这篇文章的作者,点这里就到,总结的很好。直接贴过来~
四塔问题:设有A,B,C,D四个柱子(有时称塔),在A柱上有由小到大堆放的n个盘子。
今将A柱上的盘子移动到D柱上去。可以利用B,C柱作为工作栈用,移动的规则如下:
①每次只能移动一个盘子。
②在移...
分类:
其他好文 时间:
2014-05-02 21:10:00
阅读次数:
376