目录目录
题目
思路1
AC代码
缺陷
思路2
AC代码题目
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
push(x) – Push element x onto stack.
pop() – Removes the ele...
分类:
其他好文 时间:
2015-03-02 13:08:54
阅读次数:
141
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get ...
分类:
其他好文 时间:
2015-02-28 18:45:25
阅读次数:
116
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6,...
分类:
其他好文 时间:
2015-02-24 22:10:07
阅读次数:
215
【题目】Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Rem...
分类:
其他好文 时间:
2015-02-19 17:29:31
阅读次数:
263
02-1. Reversing Linked List (25)时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, YueGiven a constant K and a singly linked list L, you are suppos...
分类:
其他好文 时间:
2015-02-16 20:58:02
阅读次数:
310
标题:Sort List通过率:21.3%难度:中等Sort a linked list inO(nlogn) time using constant space complexity.本题就是一个排序的问题,但是是针对单向链表去处理,那么问题关键就是怎么去处理链表,时间复杂度为nlogn,所以可以...
分类:
其他好文 时间:
2015-02-16 11:41:43
阅读次数:
146
Sort a linked list in O(n log n) time using constant space complexity.
可以利用归并排序解决该问题。普通的归并排序算法时间复杂度为O(nlogn),空间复杂度为O(n),因为需要建立两个数组来存储原来数组的值,这两个数组的长度加起来恰好为原数组的长度。但是对于链表可以省去复制两个已经排好序的数组的操作,从而使空间复杂度...
分类:
其他好文 时间:
2015-02-15 23:08:39
阅读次数:
175
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.
Your algorithm should use only constant space. Y...
分类:
其他好文 时间:
2015-02-14 21:23:48
阅读次数:
246
欢迎大家阅读参考,如有错误或疑问请留言纠正,谢谢
Sort List
Sort a linked list in O(n log n) time using constant space complexity.
// 归并排序法:在动手之前一直觉得空间复杂度为常量不太可能,因为原来使用归并时,都是 O(N)的,需要复制出相等的空间来进行赋值归并。对于链表,实际...
分类:
其他好文 时间:
2015-02-14 17:34:48
阅读次数:
166
1. By Default, const Objects Are Local to a File
默认情况下,const对象是本地的
这是《C++ primary 5th》里的原文
When a const object is initialized from a compile-time constant, such as in our
definition of bufSize...
分类:
编程语言 时间:
2015-02-13 16:33:37
阅读次数:
184