Sort a linked list using insertion sort.简单插入排序,先写个插入一个值到链表里的函数,再遍历整个链表,一个一个把值插入新链表中: 1 public ListNode insertionSortList(ListNode head) { 2 i...
分类:
编程语言 时间:
2014-09-19 07:41:55
阅读次数:
165
第一个问题可以抽象为这样:给定一个数组A,和一个数t,用数组里的一些数求和得到t,数组里的数可以重复使用,写一个算法,使得使用A中最少的数来表示t。比如:[2,4,6,9],18==>[9,9]dfs问题//numbers要从大到小,一个sort搞定,result存放结果bool dfs(vecto...
分类:
其他好文 时间:
2014-09-18 22:02:24
阅读次数:
162
快速排序
void quick_sort(int array[], int begin, int end)
{
if(end > begin)
{
int pivot = begin;
int last_small = begin;
int i = end;
while(last_small != i)
{
if(array[i] <= array[pivot])
...
分类:
其他好文 时间:
2014-09-18 18:54:34
阅读次数:
181
linux的文件名是大小写敏感的,所以,我们要将代码中include的头文件大小写做个转换。手动修改——当我没说……用脚本去解决,之前我用perl写过这样功能的脚本,但是时间久远,我已经找不到了。简单分析一下,大概是一下几步找到所有的被包含过的头文件,grep/sort/uniq对每一个头文件,如果...
分类:
其他好文 时间:
2014-09-18 18:40:54
阅读次数:
169
[leetcode]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 the integers 0, 1, and 2 to represent the color red, white, and...
分类:
其他好文 时间:
2014-09-18 13:21:43
阅读次数:
164
Here is the basic algorithm about merge sort:def merge(s1,s2,s): i=j=0 while i + j < len(s): if j == len(s2) or (i < len(s1) and s1[i] < ...
分类:
编程语言 时间:
2014-09-18 11:17:13
阅读次数:
165
我比较了一下sort和一个自己写的o(n)的程序的运行时间。惊奇发现sort的速度几乎和直接用python写的o(n)的程序运行时间接近先上代码sort的测试代码import randomimport syslen_test_arr = int(sys.argv[1])test_arr = [ran...
分类:
编程语言 时间:
2014-09-18 09:39:33
阅读次数:
228
Sort a linked list in O(n log n) time using constant space complexity.记得Insert Sort List, 那个复杂度是O(N^2)的,这里要求O(nlogn),所以想到merge sort, 需要用到Merge Two Sor...
分类:
其他好文 时间:
2014-09-18 01:57:43
阅读次数:
199
1 package sort; 2 3 import java.util.ArrayList; 4 import java.util.Random; 5 6 public class Sort 7 { 8 9 public static Random r = new...
分类:
其他好文 时间:
2014-09-17 21:51:22
阅读次数:
368
make_heap原型:
std::make_heap
default (1)
template
void make_heap (RandomAccessIterator first, RandomAccessIterator last);
custom (2)
template
void make_heap (Rando...
分类:
其他好文 时间:
2014-09-17 18:43:42
阅读次数:
241