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...
分类:
其他好文 时间:
2014-07-28 00:28:19
阅读次数:
273
题目:Sort a linked list in O(n log n) time using constant space complexity.题解:考虑到要求用O(nlogn)的时间复杂度和constant space complexity来sort list,自然而然想到了merge sor....
分类:
编程语言 时间:
2014-07-26 09:51:57
阅读次数:
307
题目:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.F....
分类:
编程语言 时间:
2014-07-26 09:51:47
阅读次数:
215
题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题解:Merge k sorted linked list就是merge 2 sorted li....
分类:
编程语言 时间:
2014-07-26 05:44:37
阅读次数:
304
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
思路:笨办法是每个节点再开辟一个属性存放是否访问过,这样遍历一遍即可知道是否有环。但为了不增加额外的空间,可以设置两个指针,一个一次走一步,另一个一次走两步...
分类:
编程语言 时间:
2014-07-25 11:09:21
阅读次数:
206
题目:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep c....
分类:
编程语言 时间:
2014-07-24 10:00:33
阅读次数:
310
题目:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flatten...
分类:
编程语言 时间:
2014-07-24 09:55:43
阅读次数:
211
题目:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->....
分类:
编程语言 时间:
2014-07-24 09:49:43
阅读次数:
204
题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve t....
分类:
编程语言 时间:
2014-07-23 12:27:46
阅读次数:
290
题目:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. Af...
分类:
编程语言 时间:
2014-07-23 12:20:26
阅读次数:
243