摘要:最近一个项目需要正则搜索MongoDB,400多万的数据一次查询要20s以上,需要建立一个前端索引服务。本着部署简单、开发容易的原则,找到了xapian这个索引库。 我使用的是Python的接口,xapian的服务API相当简单,基本的流程是打开库、设置查询条件、取得查询结果。 _enquire = xapian.Enquire(xapian.Database(conf.IDX_DATABASE)...
阅读全文
摘要:看了《千年难题》,第一章是黎曼猜想。里面有两个我很感兴趣的问题:一是关于函数的图形表示方式,比如z=sin(xy)的图像,二是大数的因子分解方式。 专业的数学软件应该能够很容易的生成各种函数图像,但是我要探求的是作为业余人士利用免费工具和简单的编程语言来描绘函数图形。scipy里面的工具可以做这部分工作。 from mpl_toolkits.mplot3d import Axes3D
from ...
阅读全文
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. to...
阅读全文
摘要:Encode a string by counting the consecutive letter. (i.e., "aaaabbxxxyyz" might become "a4b2x3y2z1"). 分析: 这个问题是一个基本的数据压缩算法,将相邻的字符计数存储。解法没有什么特别需要注意的地方,按部就班的实现代码就可以了。 class Solution: # @param s,...
阅读全文
摘要:Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose a sorted array is rotated at some pivot unknown ...
阅读全文
摘要:Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cas...
阅读全文
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactl...
阅读全文
摘要:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in a...
阅读全文
摘要:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must...
阅读全文
摘要:Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, whe...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. 分析: 对一组字符串找到最长公共前缀。 因为只是找前缀所以可以以第一个字符串为基础,按个字符与其它字符串比较,直到有字符串已经遍历完或者碰到不一致的字符,返回到当前为止第一个字符串的前缀即可。 class Solution...
阅读全文
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplicate exists in the arr...
阅读全文