Sort
文章平均质量分 77
iteye_17352
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode - Merge Intervals
Given a collection of intervals, merge all overlapping intervals. [分析] 这题思路不难,将输入的区间数组按左边界排序然后合并。但是调试了很久,收获是熟悉了些Java语法。首先,忘记对ArrayList排序可以使用Collections.sort(),不厌其烦地在ArrayList和数组间转换为了能使用Arrays.sort进...原创 2015-07-12 09:45:10 · 124 阅读 · 0 评论 -
Leetcode - Insert Interval
[分析] 这道题思路直接,但bug free需要费些心力。第一版未优化的代码笔记长,未贴。 下面给出的两个实现,实现1是使用二分法找到新区间应插入的位置,然后检查是否需要和上一个区间合并(容易忽略),最后同后面的区间逐个检查是否需要合并。无需额外空间,Code Ganker 指出这种做法严格上非O(N),因为合并时有数组remove操作,最坏情况下是O(N^2),但跑leetcode测试用例这...原创 2015-08-14 10:12:26 · 190 阅读 · 0 评论 -
Leetcode - Meeting Rooms II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required. For example, Given [[0, 30],[5, 10...原创 2015-08-15 16:28:21 · 131 阅读 · 0 评论 -
Leetcode - Sort List
Sort a linked list in O(n log n) time using constant space complexity. [分析] 将链表二分,递归排序子链表,然后merge 已排序的两子链表。 [code="java"] public class Solution { public ListNode sortList(ListNode head) { ...原创 2015-08-15 17:41:46 · 118 阅读 · 0 评论 -
Leetcode - Insertion Sort List
Sort a linked list using insertion sort. [分析] 数组的插入排序通常做法是从当前元素往前遍历找到插入点,而单向链表无法回溯,于是每次从头开始寻找插入点。使用dummy额外节点技巧可使实现更简洁。 开始未将已排序部分和未排序部分分开,会死循环从而OutOfMemory,简单带入2->1 可看出bug。 [code="java"] publ...原创 2015-08-15 19:27:22 · 123 阅读 · 0 评论 -
Leetcode - Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be ve...原创 2015-08-15 20:16:03 · 143 阅读 · 0 评论 -
Leetcode - Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Try to solve it in linear time/space. Return 0 if the array contains less than 2 elements...原创 2015-08-16 10:17:57 · 149 阅读 · 0 评论 -
Leetcode - Shortest Word Distance II
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameters. How would you ...原创 2015-08-18 07:25:35 · 122 阅读 · 0 评论 -
Leetcode - First Missing Positive
[分析] 将各个正数放入相应下标处,使之满足nums[nums[i] - 1] = nums[i],则一遍扫描后值在数组长度范围内的都按序排列了,然后二遍扫描遇到第一个打破秩序的位置i,则 i + 1就是第一个缺失的正数。 [ref] 解析清楚的Code Ganker博客:[url]http://blog.youkuaiyun.com/linhuanmars/article/details/208845...原创 2015-08-20 07:45:30 · 138 阅读 · 0 评论
分享