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 nothing
def reorderList(self, head):
if None == head or None == ...
分类:
编程语言 时间:
2014-07-16 17:23:30
阅读次数:
207
题目分析见这里
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
在分析安卓源码过程中看到几处使用变长结构体的例子,比如下面的结构体:
struct command
{
/* list of commands in an action */
struct listnode clist;
int (*func)(int nargs, char **args);
int nargs;
char *args[1];
...
分类:
其他好文 时间:
2014-07-16 16:16:29
阅读次数:
381
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.#include#includeusing namespace std;struct ListNode ...
分类:
其他好文 时间:
2014-07-16 15:17:03
阅读次数:
188
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
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
1.看源码必须搞懂Android的数据结构。在init源代码中双向链表listnode使用很多,它只有prev和next两个指针,没有任何数据成员。这个和linux内核的list_head如出一辙,由此可见安卓深受linux内核的影响的。本来来分析一下这个listnode数据结构。
这里需要考虑的一个问题是,链表操作都是通过listnode进行的,但是那不过是个连接件,如果我们手上有个宿主结构,...
分类:
移动开发 时间:
2014-07-14 18:13:24
阅读次数:
435
int main(){}void addTotail(ListNode *& pHead, int value){ ListNode *node = new ListNode(); node->value = value; node->pNext = NULL; ListNode *p = pHea...
分类:
其他好文 时间:
2014-07-13 21:11:59
阅读次数:
173