2013年12月2日

Sort List

摘要: Sort a linked list inO(nlogn) time using constant space complexity.思路:归并排序。题目要求固定空间,不知道这种递归实现的算不算固定空间。代码: 1 ListNode *sortList(ListNode *head, int length){ 2 if(length next;14 }15 half = tmp->next;16 tmp->next = NULL;17 ListNode *first = sortList(head, l),... 阅读全文

posted @ 2013-12-02 19:47 waruzhi 阅读(187) 评论(0) 推荐(0) 编辑

Merge Intervals

摘要: Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].思路:先对数据进行排序,然后逐个插入。注意在使用sort的时候,最开始出现错误,后来把myCmp改成static的以后就解决了。代码: 1 int max(int a, int b){ 2 if(a > b) 3 return a; 4 return b; 5 ... 阅读全文

posted @ 2013-12-02 16:43 waruzhi 阅读(186) 评论(0) 推荐(0) 编辑

导航