摘要: Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may not... 阅读全文
posted @ 2017-01-13 14:04 copperface 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263/** * Definition for singly-linked list. * struct ListNode { * int val; * L... 阅读全文
posted @ 2017-01-13 14:04 copperface 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.分析算法1:类似于归并排序,将Merge k 个的问题,拆分成Merge 2 个的子任务,然后递归回溯。算法复杂度 O(nlogn)算法2:使用最小堆。维护一个最大 大小 k 的最小堆,每次从堆顶pop出... 阅读全文
posted @ 2017-01-13 14:03 copperface 阅读(242) 评论(0) 推荐(0) 编辑