数组中重复项的去除一维数组的重复项:使用array_unique函数即可,使用实例如下:结果如下:Array ( [0] => apple [1] => banana [2] => pear [4] => wail [5] => watermalon ) 。二维数组的重复项:对于二维数组咱们分两种情...
分类:
Web程序 时间:
2014-09-24 13:29:26
阅读次数:
212
代码中的两个方法都是动态规划。第二种方法很好理解,第一种方法是在第二种方法基础上进行优化,即“降维”,变成一维动态规划。如soulmachine所写,对于f[j] = f[j - 1] + f[j];右边的f[j],表示老的f[j],与公式中的f[i-1][j] 对应左边的f[j],表示更新后的f[...
分类:
其他好文 时间:
2014-09-23 19:18:05
阅读次数:
276
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,
[1,1,2] have the following unique permutations:
[1,1,2], [1,2,1],
and [2,1,1]....
分类:
其他好文 时间:
2014-09-23 17:07:24
阅读次数:
222
题目:
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?
For example,
Given n = 3, there are a total of 5 unique BST's.
1 3 3 2...
分类:
其他好文 时间:
2014-09-22 20:55:03
阅读次数:
203
You are given a binary tree in which each node contains a value. Design an algorithm to print all paths which sum up to that value. Note that it can b...
分类:
其他好文 时间:
2014-09-21 12:31:50
阅读次数:
180
题目:给定一个string,找出第一个string里的unique character,如“cisco”的话就应该是i,“cat”的话就是c。
第一种方法是用LinkedHashMap保留数据的顺序,过一遍string,对字符进行计数,然后找到第一个数量为1的字符即可。
第二种方法是用一个HashSet来存已经重复的字符,然后用个arraylist来存仅出现了一次的字符。
第三种方法是用Ha...
分类:
其他好文 时间:
2014-09-21 09:11:30
阅读次数:
293
Mac添加环境变量的三种方法法一:系统级,修改/etc/paths(每一行是一个环境变量)法二:系统级,方便管理1.创建一个文件:sudo touch /etc/paths.d/mysql2.用 vim 打开这个文件(如果是以 open -t 的方式打开,则不允许编辑):sudo vim /etc/...
分类:
其他好文 时间:
2014-09-21 00:24:49
阅读次数:
314
一、key与primary key区别CREATE TABLE wh_logrecord (logrecord_id int(11) NOT NULL auto_increment,user_name varchar(100) default NULL,operation_time datetime...
分类:
数据库 时间:
2014-09-21 00:08:09
阅读次数:
311
设计多对多表时解决重复问题目前流行两种设计方式:方式一 是在中间表中建一个单独的id主键,与业务表关联的键设置为unique唯一;干事二:联合主键的方式,该方式中间表不会有与业务表无关的主键,即把与业务表关联的键进行联合作为主键下面是使用pd来设计表的两种详细方式方式一:中间表采用一个单独的id主键...
分类:
其他好文 时间:
2014-09-20 20:47:19
阅读次数:
470
次小生成树
求最小生成树时,用数组Max[i][j]来表示MST中i到j的最大边权。
求完后,直接枚举所有不在MST中的边,替换掉最大边权的边,更新答案。
#include
#include
#include
using namespace std;
const int maxn = 110;
const int INF = 1e9;
bool vis[maxn];
in...
分类:
其他好文 时间:
2014-09-20 02:17:36
阅读次数:
203