1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * ...
分类:
编程语言 时间:
2014-07-16 17:45:41
阅读次数:
226
刚才写了k个,顺手写个2个的,在链表的归并排序中很有用,效率非常好 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next;...
分类:
其他好文 时间:
2014-07-16 17:42:41
阅读次数:
275
题目分析见这里
class Solution:
# @param head, a ListNode
# @return a list node
def detectCycle(self, head):
if None == head or None == head.next:
return None
pfast = ...
分类:
编程语言 时间:
2014-07-16 17:18:53
阅读次数:
248
[LeetCode]Populating Next Right Pointers in Each Node...
分类:
其他好文 时间:
2014-07-16 11:29:23
阅读次数:
143
class Solution:
# @param head, a ListNode
# @return a boolean
def hasCycle(self, head):
if None == head or None == head.next:
return False
pfast = head
...
分类:
编程语言 时间:
2014-07-16 09:50:21
阅读次数:
271
1.结点
链表中用来存储一个数据的存储单元。
一个链表至少需要由两部分组成,就是数据域和指针域,一般形式的结点定义为:
struct node
{
Elem data; //Elem类型泛指基本数据类型
struct node *next;
}
typedef struct node Elemsn;
以上两步等价于:
typedef struct node
{...
分类:
其他好文 时间:
2014-07-15 13:01:24
阅读次数:
281
Sort a linked list using insertion sort.
class Solution {
public:
ListNode *insertionSortList(ListNode *head) {
if(head == NULL || head->next == NULL)
return head;
Lis...
分类:
其他好文 时间:
2014-07-15 12:22:53
阅读次数:
244
pairs
Returns three values: the next function, the table t, and nil, so that the
construction
for k,v in pairs(t) do body end
will iterate over all key–value pairs of table t.
See functi...
分类:
其他好文 时间:
2014-07-14 18:39:58
阅读次数:
317
1.看源码必须搞懂Android的数据结构。在init源代码中双向链表listnode使用很多,它只有prev和next两个指针,没有任何数据成员。这个和linux内核的list_head如出一辙,由此可见安卓深受linux内核的影响的。本来来分析一下这个listnode数据结构。
这里需要考虑的一个问题是,链表操作都是通过listnode进行的,但是那不过是个连接件,如果我们手上有个宿主结构,...
分类:
移动开发 时间:
2014-07-14 18:13:24
阅读次数:
435
Sort a linked list using insertion sort.题解:实现链表的插入排序。要注意的地方就是,处理链表插入的时候尽量往当前游标的后面插入,而不要往前面插入,后者非常麻烦。所以每次利用kepeler.next.val和head.val比较大小,而不是kepeler.val...
分类:
其他好文 时间:
2014-07-14 17:47:19
阅读次数:
207