摘要: 思路1: class Solution { public: // 两个指针,p, q, q指向第二个,preP是p之前 ListNode *swapPairs(ListNode *head) { if(head == NULL) return NULL; auto p = head; auto q = head->next; ... 阅读全文
posted @ 2015-02-26 11:07 薇清浅 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 题意: 将k个已排好序的链表合并为一个非下降排序的链表。 思路: 将每个链表的表头元素取出来,建立一个小顶堆,因为k个链表中都排好序了,因此每次取堆顶的元素就是k个链表中的最小... 阅读全文
posted @ 2015-02-26 10:21 薇清浅 阅读(6693) 评论(0) 推荐(0) 编辑