Merge k Sorted ListsMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.两种实现方法,第一种采用优先队列,第二种采用分治/**
* Definition for singly-linked list.
* struct ListNo...
分类:
其他好文 时间:
2014-11-27 20:36:39
阅读次数:
227
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.
After removing the second node from the end, the l...
分类:
其他好文 时间:
2014-11-27 09:14:31
阅读次数:
197
Sort a linked list in O(n log n) time using constant space complexity.Analsys:We use Merge Sort.NOTE: We should practice other sort algorithm, linke Q...
分类:
其他好文 时间:
2014-11-27 01:35:39
阅读次数:
213
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne...
分类:
编程语言 时间:
2014-11-26 23:59:34
阅读次数:
350
Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the or...
分类:
其他好文 时间:
2014-11-26 20:34:57
阅读次数:
238
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
这个题目如果没有空间复杂度O(1)的限制,我可以想到的方法就是:遍历整个list,将每个节点的地址存入一个vector,如果发现某个节点的next的地址已经在vec...
分类:
其他好文 时间:
2014-11-26 19:02:15
阅读次数:
119
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
#include
#include
...
分类:
其他好文 时间:
2014-11-26 18:59:03
阅读次数:
155
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 space?
这个题目跟Linked List Cycle一样,我也没有能够自己独立找到解决方法,...
分类:
其他好文 时间:
2014-11-26 18:57:10
阅读次数:
126
原题地址:https://oj.leetcode.com/problems/partition-list/题目内容:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nod...
分类:
其他好文 时间:
2014-11-26 18:47:01
阅读次数:
196
Sort a linked list in O(n log n) time using constant space complexity....
分类:
编程语言 时间:
2014-11-26 16:37:32
阅读次数:
172