题目:
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 ...
分类:
编程语言 时间:
2015-07-18 12:44:13
阅读次数:
148
贪心算法是使所做的选择看起来都是当前最优的,通过所做的局部最优选择来产生一个全局最优解。
其具有的性质如下:
1)贪心选择性质:一个全局最优解可以通过局部最优(贪心)选择来达到。即,在考虑如何做选择时,我们只考虑对当前问题最佳的选择而不考虑子问题的结果。
这一点是贪心算法不同于动态规划之处:在动态规划中,每一步都要做出选择,但是这些选择依赖于子问题的解。因此,解动态规划问...
分类:
编程语言 时间:
2015-07-18 12:45:42
阅读次数:
2177
1.匿名函数
onclick=function(){}就是匿名函数.
2.匿名函数的回调函数
var one=function(){
return 1;
};
var two=function(){
return 2;
};
function fn(a,b){
return a()+b();//加上括号证明这是函数
} alert(fn(one,two));
运行结...
分类:
编程语言 时间:
2015-07-18 12:43:17
阅读次数:
133
题目:
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).
For example,
S = "ADOBECODEBANC"
T = "ABC"
Minimum windo...
分类:
编程语言 时间:
2015-07-18 12:38:58
阅读次数:
196
思想:图G是不带权的无向连通图,一条边的长度计为1,因此,求带顶点u和顶点v的最短的路径即求顶点u和顶点v的边数最少的顶点序列。利用广度优先遍历算法,从u出发进行广度遍历,类似于从顶点u出发一层一层地向外扩展,当第一次找到顶点v时队列中便包含了从顶点u到顶点v最近的路径,如图所示,再利用队列输出最路径(逆路径),所以设计成非循环队列。
...
分类:
编程语言 时间:
2015-07-18 12:40:05
阅读次数:
358
题目:
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
For example,
If n = 4 and k = 2, a solution is:
[
[2,4],
[3,4],
[2,3],
[1,2],
[1,3],
...
分类:
编程语言 时间:
2015-07-18 12:37:37
阅读次数:
102
基本思想在一组元素中选择具有最小排序码的元素,若它不是这组元素中的第一个元素,则将它与这组元素中的第一个元素对调;在未排序的剩下的元素中重复执行以上步骤,直到剩余元素只有一个为止。代码private void selectSort(int[] a, int left, int right) {
for (int i = left; i < right; i++) {
int...
分类:
编程语言 时间:
2015-07-18 12:37:05
阅读次数:
167
快速排序的思想(双边扫描)
快速排序就像一个数据快,前后各有一个下标(指针)i/j,随机选取一个元素作为标志位,存储在临时变量中(tmp),j从后向前移动(j--)直到碰到比tmp还要小的数时与i交换,此时i开始像后走,直到遇到第一个比tmp大的数,与j交换。
递归直至完成。
运行环境:ubuntu 14.04 kylin
#include
#include
void swap(l...
分类:
编程语言 时间:
2015-07-18 12:34:43
阅读次数:
550
装箱(inbox)和拆箱(outbox)
代表了类类型和基本类型之间的转换行为。
手动版本:
Integer b = new Integer(10);
Int a = b.intValue;
自动版本:
Integer b=30; à Integer b=new Integer(30);
Int a=b; ...
分类:
编程语言 时间:
2015-07-18 12:35:16
阅读次数:
145
题目:
Given a set of distinct integers, nums, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.
...
分类:
编程语言 时间:
2015-07-18 12:36:29
阅读次数:
151
原以为是jdk的环境变量配置错误了,于是从网上找了各种配置环境变量的方法,也注意空格的问题,可不管怎么改,还是这样报错!后来在网上看到一种奇怪的方法,我也不知道为什么这样就OK了?
方法:进入你的eclipse目录,用终端打开,切换到root下,然后输入:
mkdir jre
cd jre
ln -s 你的JDK目录/bin bin
如果你知道为什么希望能贴出来告诉我,谢谢...
分类:
编程语言 时间:
2015-07-18 12:32:22
阅读次数:
136
异常值检测一、实验说明1. 环境登录无需密码自动登录,系统用户名shiyanlou,密码shiyanlou2. 环境介绍本实验环境采用带桌面的Ubuntu Linux环境,实验中会用到程序:1. LX终端(LXTerminal): Linux命令行终端,打开后会进入Bash环境,可以使用Linux命...
分类:
编程语言 时间:
2015-07-18 12:30:25
阅读次数:
173
先在官网分别下载安装python2.7.10和python3.4.3,然后进入Python 2.7.10的安装目录C:\Python27,将python.exe和pythonw.exe分别重命名为python27.exe和pythonw27.exePython 3.4.3的安装目录C:\Python...
分类:
编程语言 时间:
2015-07-18 12:28:21
阅读次数:
124
一、泛型类 在类名后面加上类型T,如下: class RandomList { private ArrayList storage = new ArrayList(); private Random rand = new Random(47); public void add(T item) { s...
分类:
编程语言 时间:
2015-07-18 12:28:38
阅读次数:
147
回归一、实验说明1. 环境登录无需密码自动登录,系统用户名shiyanlou,密码shiyanlou2. 环境介绍本实验环境采用带桌面的Ubuntu Linux环境,实验中会用到程序:1. LX终端(LXTerminal): Linux命令行终端,打开后会进入Bash环境,可以使用Linux命令2....
分类:
编程语言 时间:
2015-07-18 12:23:59
阅读次数:
423
1.包2.运算符public class Operator { public static void main(String[] args) { int a = 5; System.out.println("a = " + a); //a = -a; //...
分类:
编程语言 时间:
2015-07-18 12:20:33
阅读次数:
111
在IDEA 的子 Maven Module 中使用 compile 进行编译, 一开始提示从私有远程仓库找不到 pom, 再次进行编译提示Could not resolve dependencies for project ......解决方法是 首先将 Parent Module(root 项目)...
分类:
编程语言 时间:
2015-07-18 12:20:19
阅读次数:
177