给定一个整数X和整数A0,A1,…,AN-1,后者已经预先排序并在内存中,求下标i使得Ai = X , 如果X不在数据中则返回i = -1 。明显的解法是从左往右扫描,花费线性时间。但是这个算法没有用到该表已经排序这个事实。折半检索(binary search,二分法检索)策略:/** * Perf...
分类:
其他好文 时间:
2014-07-16 23:25:47
阅读次数:
233
在ES裡, 更新documents到index不是一件簡單的事情, 我們得在這裡留個心眼.眾所皆知RESTful風格使用HTTP的動詞來進行所謂的Update, ES也是如此.要注意到ES的更新有兩種方式整個docment更新(取代,覆蓋)根據某個field更新(count += 3, append...
分类:
其他好文 时间:
2014-07-16 23:20:03
阅读次数:
246
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or...
分类:
其他好文 时间:
2014-07-16 23:16:32
阅读次数:
156
MySQL purge log简单吗?简单: purge log的功能很简单,purge master logs to 指定一个binlog,然后删除之前的文件系统上的binlog文件,并更新binlog.index文件。复杂: 需要保证purge的原子操作吗, 怎么保证, 有崩溃恢复吗?之前没有读...
分类:
数据库 时间:
2014-07-10 12:32:45
阅读次数:
270
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 ...
分类:
其他好文 时间:
2014-07-10 11:24:15
阅读次数:
229
OpenERP对象支持的字段类型有,基础类型:char, text, boolean, integer, float, date, time, datetime, binary;复杂类型:selection, function, related;关系类型:one2one, one2many, man...
分类:
其他好文 时间:
2014-07-10 11:13:07
阅读次数:
339
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.方法一:最先想到的就是递归,注...
分类:
其他好文 时间:
2014-07-10 09:58:40
阅读次数:
224
Given two binary strings, return their sum (also a binary string).
分类:
其他好文 时间:
2014-07-09 23:52:48
阅读次数:
383
#include "my_file.h"
//将文件内容拷贝到指定文件
int mycopy(const char *filename)
{
ifstream infile(filename, ios::binary);
ofstream outfile("TRACE.txt", ios::binary);
if (!infile.is_open() || !outfile...
分类:
其他好文 时间:
2014-06-28 08:46:56
阅读次数:
199
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
For example:
Given the below binary tree and sum
= 22,
5
/ ...
分类:
其他好文 时间:
2014-06-28 07:31:28
阅读次数:
214