sort
148. Sort List
题目:Sort a linked list in O(n log n) time using constant space complexity.解答:(对于discuss中第二个最优解的解释)根据时间复杂度的要求,很容易想到应该用merge sort的方法来做,那么就有两个步骤,分和法。先把整个list分成两部分,这里可以用找中间值的方法,在找中间值的同时,标记一下中间值
技术开发
2016年06月20日
179. Largest Number
这道题开始想容易陷入一个误区:我要怎么比较这两个单独的数,使得它们拼起来的结果最大呢?然而如果真的仔细比较这两个数最后得出一个结论,代码会很长,楼主已经试过了。。。后来转念一想,直接比较两个数拼成的结果不就好了,长度一样,所以省去了很多麻烦。程序如下:
public String largestNumber(int[] nums) {
//直接暴力地把两个数合成一个Stri
技术开发
2016年06月21日
75. Sort Colors
题目:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use th
技术开发
2016年06月21日
147. Insertion Sort List
注意新的list跟原来的list是不相连的,然后把各个状态的点记录好就行:
public ListNode insertionSortList(ListNode head) {
if (head == null || head.next == null) return head;//We started a new list here, not the original o
技术开发
2016年06月21日
274. H-Inde
题目:Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wik
技术开发
2016年06月22日
164. Maimum 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 e
技术开发
2016年06月22日
php二维数组指定其键名对其排序的方法
安利个小李子先'red', '5'=>'green', 'name'=>'tom'];$other=['5'=>'new red','name'=>'jessy'];$new_a=array_merge($arr,$other);$new_b=array_merge_recursive($other,$arr);var_dump($new);array_merg
业界
2016年07月20日
[LintCode] Sort Integers II [Merge-sort, Quick-sort, Heap-sort]
ProblemGiven an integer array, sort it in ascending order. Use quick sort, merge sort, heap sort or any O(nlogn) algorithm.ExampleGiven [3, 2, 1, 4, 5], return [1, 2, 3, 4, 5].Note考察对Heap
技术开发
2016年07月27日