问题描述如下:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra s...
分类:
其他好文 时间:
2014-07-03 21:00:48
阅读次数:
401
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t...
分类:
其他好文 时间:
2014-07-03 20:32:55
阅读次数:
429
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
分类:
其他好文 时间:
2014-07-03 19:10:40
阅读次数:
201
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu...
分类:
其他好文 时间:
2014-07-03 18:57:04
阅读次数:
193
Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个排序列表解题思路是:取出 k个元素进行堆排序,每次取出最小的元素,插入链表中即可注意本题利用了c++...
分类:
其他好文 时间:
2014-07-02 20:16:54
阅读次数:
273
Reverse a linked list from position m to n. Do it in-place and in one-pass.
分类:
其他好文 时间:
2014-07-02 20:12:57
阅读次数:
182
【题目】
Sort a linked list in O(n log n) time using constant space complexity.
【题意】
排序一个链表,要求时间复杂度O(nlogn),使用常量空间
【思路】
nlogn的复杂度,用归并排序求解...
分类:
其他好文 时间:
2014-07-02 09:25:40
阅读次数:
252
Sort a linked list in O(n log n)
time using constant space complexity.
看到O(n log n)的排序算法,适合单链表的首先想到的就是归并排序
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* Lis...
分类:
其他好文 时间:
2014-07-02 08:47:34
阅读次数:
239
【题目】
Sort a linked list using insertion sort.
【题意】
用插入排序方法排序链表
【思路】
直接搞...
分类:
其他好文 时间:
2014-07-02 08:33:49
阅读次数:
200
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first
two lists.
代码如下:
* Definition for singly-linked list.
* struct L...
分类:
其他好文 时间:
2014-07-02 07:23:59
阅读次数:
159