随笔分类 - sorting
摘要:This solution is just a java version derived from this post. At first, lets look at the edge cases - Now the main algorithm works in following steps -
阅读全文
摘要:We can also do it without modifying the input by using a variable prev to hold the a[i-1]; if we have to lower a[i] to match a[i-1] instead of raising
阅读全文
摘要:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given nums = [0, 1, 3] return 2. Note: Your algorithm should run i...
阅读全文
摘要: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 n
阅读全文
摘要:Implement a Comparator<Interval> Syntax: don't forget the public sign when defining a function
阅读全文
摘要:这道题跟Insertion Sort List类似,要求我们用O(nlogn)算法对链表进行排序,但是并没有要求用哪一种排序算法,我们可以使用归并排序,快速排序,堆排序等满足要求的方法来实现。对于这道题比较容易想到的是归并排序,因为我们已经做过Merge Two Sorted Lists,这是归并排
阅读全文
摘要:数组的题常用方法 :排序、最大值指针边走边找、最小值指针边走边找,数组的其他指针位置—顺序遍历, 逆序遍历,其他指针与最大值指针比较的后果或最小值指针 先想排序能否做: Stack 画图: 利用相对位置和大小pop找到最左边的位置, 和最右边的位置, 利用栈内的元素都是最小的特点, 找到要排序的su
阅读全文
摘要:最好用栈来想问题, 当前元素比栈内元素大 或小的时候怎么办, 最后优化成单个变量, 数组的题除了常用动归, 也常用栈, 用动归前看看解决了重复计算问题吗? 得想出状态转移方程来, 不然就不是动归
阅读全文
摘要:其实是一种特别顺序的排序, 所以就用quicksort-partition, 不过比较的元素和设计互相patition, partition 的比较因为是有equals的, 所以得用三个指针遍历 考点: partition 的设计, pivot 的选择 , 另一方的排序通过nuts排好后的数组再排,
阅读全文
摘要:Let's say nums is [10,11,...,19]. Then after nth_element and ordinary partitioning, we might have this (15 is my median): I rewire it so that the firs
阅读全文
摘要:refer to: https://discuss.leetcode.com/topic/60394/easy-concept-with-python-c-java-solution E.g.input: [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]subar
阅读全文
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers.
阅读全文
摘要:http://www.cnblogs.com/EdwardLiu/p/6197086.html https://leetcode.com/problems/heaters/#/description Binary Search My solution: Be careful in my binary
阅读全文

浙公网安备 33010602011771号