常见排序算法主要有:插入排序(直接插入排序、希尔排序)选择排序(直接选择排序、堆排序)交换排序(冒泡排序、快速排序)归并排序基数排序外部排序一.直接插入排序算法思想:在一个待排序列中,从第二个元素开始,依次进行排序,每次都将待排序元素从后往前,依次与前面的元素进行比较,从而将带排序元素移动到一个合适...
分类:
其他好文 时间:
2014-05-21 20:03:36
阅读次数:
353
【题目】
Given an unsorted integer array, find the first missing positive integer.
For example,
Given [1,2,0] return 3,
and [3,4,-1,1] return 2.
Your algorithm should run in O(n) time and uses constant space.
【题意】
给定一个数组,找出第一个缺失的正数。时间复杂度O(n)
...
分类:
其他好文 时间:
2014-05-21 17:13:07
阅读次数:
219
【题目】
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
Each number in C may only be used once in the combination.
Note:
All numbers (including target) will be ...
分类:
其他好文 时间:
2014-05-21 15:55:25
阅读次数:
259
这一篇文章专门整理一下研究过的Android面试题,内容会随着学习不断的增加,如果答案有错误,希望大家可以指正
1.简述Activity的生命周期
当Activity开始启动的时候,首先调用onCreate(),onStart(),onResume()方法,此时Activity对用户来说,是可见的状态
当Activity从可见状态变为被Dialog遮挡的状态的时候,会调用on...
分类:
移动开发 时间:
2014-05-21 15:43:02
阅读次数:
333
【题目】
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
The same repeated number may be chosen from C unlimited number of times.
Note:
All numbers (including target) w...
分类:
其他好文 时间:
2014-05-21 15:21:28
阅读次数:
292
【题目】
The count-and-say sequence is the sequence of integers beginning as follows:
1, 11, 21, 1211, 111221, ...
1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.
Given an integer n, generate...
分类:
其他好文 时间:
2014-05-21 15:20:07
阅读次数:
213
问题:
求两个数的最大公约数
解法一:
欧几里得辗转相除法:
f(x,y) = GCD(x,y), 取k = x / y, b = x % y,则:x = k*y + b;
如果一个数能整除x,y,则它也能整除b,y; 而且能整除b,y的数必能整除x,y,即x,y和b,y的公约数是相同的,其最大公约数也是相同的,即f(x,y) = f(y ,x % y) (x>=y>0)...
分类:
其他好文 时间:
2014-05-21 09:28:26
阅读次数:
275
【题目】
有很多无序的数,从中找出最大的K个数。假定他们都不相等。
【解法一】
如果数据不是很多,例如在几千个左右,我们可以排一下序,从中找出最大的K个数。排序可以选择快速排序或者堆排序
[cpp] view
plaincopy
#include
#include
int cmp(const void *a,const ...
分类:
其他好文 时间:
2014-05-21 07:30:07
阅读次数:
234
【题目】
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.
The above elevation map is represente...
分类:
移动开发 时间:
2014-05-21 06:44:38
阅读次数:
359
大数相加
[cpp] view
plaincopy
#include
#include
char a[10001],b[10001],sum[10002];
int BigIntegerAdd(){
//两个数的长度
int lena = strlen(a);
int l...
分类:
其他好文 时间:
2014-05-21 06:32:32
阅读次数:
361