描述:
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...
分类:
其他好文 时间:
2015-02-01 12:12:19
阅读次数:
156
题目:
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...
分类:
其他好文 时间:
2015-01-29 17:37:16
阅读次数:
111
题目:Sort a linked list in O(n log n)
time using constant space complexity.
思路:题目要求我们使用常数空间复杂度,时间复杂度为O(nlog(n)). 满足这个时间复杂度的有快速排序,归并排序,堆排序。插入排序时间复杂度为O(n^2). 双向链表用快排比较合适,堆排序也可用于链表,单项链表适合于归并排序。我们就用归并排序的...
分类:
编程语言 时间:
2015-01-27 11:13:51
阅读次数:
190
在Ubuntu下,比葫芦画瓢,写了一个程序,居然报错!!!! 1 #include 2 3 float i = 3; 4 int j = *(int *)(&i) ; 5 6 int main (int argc , char *argv[]) 7 { 8 printf( "i = %...
分类:
其他好文 时间:
2015-01-26 21:03:23
阅读次数:
171
Sort a linked list inO(nlogn) time using constant space complexity.常见排序方法有很多,插入排序,选择排序,堆排序,快速排序,冒泡排序,归并排序,桶排序等等。。它们的时间复杂度不尽相同,而这里题目限定了时间必须为O(nlgn),符合要...
分类:
编程语言 时间:
2015-01-26 13:23:44
阅读次数:
194
对于软件开发者而言,理解和熟悉计算机内存知识是最为基础的了。今天我就来翻翻旧账,回顾回顾看看我有哪些点遗漏了,在此共同学习。
提起内存,我们常常想到三个区域:
1,静态区,静态变量 static variables / constant ,常量,静态变量就存储在静态区域,这个区域比较简单,我们就只需要知道怎么通过地址访问他就行了。
2,堆,动态变量 关键字new ,通过new 创建的对象,...
分类:
其他好文 时间:
2015-01-23 20:07:39
阅读次数:
326
Min Stack2015.1.23 12:13Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x ont...
分类:
其他好文 时间:
2015-01-23 13:19:41
阅读次数:
203
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-01-23 11:11:39
阅读次数:
131
nested condition statement 嵌套条件语句Interpreter 解释器branching programs 分支程序syntax 语法semantic语义code structure 代码结构piece of code 代码段constant time 常数时间
分类:
其他好文 时间:
2015-01-22 12:35:24
阅读次数:
200
在C#中定义常量的方式有两种,一种叫做静态常量(Compile-time constant),另一种叫做动态常量(Runtime constant)。前者用“const”来定义,后者用“readonly”来定义。对于静态常量(Compile-time constant),它的书写方式如下:publi...