Given a linked list, determine if it has a cycle in it. (Without using eatra space)//Solution: define two pointers, one moves one step each time while...
分类:
其他好文 时间:
2014-11-20 13:31:10
阅读次数:
181
Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi...
分类:
其他好文 时间:
2014-11-19 20:32:41
阅读次数:
129
异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点。可以参阅wiki 普通的双向链表 class Node {
public: int data; Node *prev; Node *next;...
分类:
其他好文 时间:
2014-11-19 20:24:07
阅读次数:
511
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.
思路很简单,由于乖乖的sort好了,就是判断下...
分类:
编程语言 时间:
2014-11-19 18:51:28
阅读次数:
242
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t...
分类:
其他好文 时间:
2014-11-19 18:31:49
阅读次数:
137
Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor...
分类:
其他好文 时间:
2014-11-19 15:41:29
阅读次数:
165
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-19 13:51:14
阅读次数:
222
Sort a linked list inO(nlogn) time using constant space complexity.O(nlogn),我们可以第一时间想到常用的二路归并排序,快速排序和堆排序,其中快排和堆排只适用于线性表,即数组,故这道编程题毫无疑问用二路归并排序;* 1. 利用一...
分类:
其他好文 时间:
2014-11-19 07:24:33
阅读次数:
225
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-...
分类:
其他好文 时间:
2014-11-19 07:18:17
阅读次数:
236
Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor...
分类:
其他好文 时间:
2014-11-19 00:15:33
阅读次数:
284