- 博客(26)
- 资源 (1)
- 收藏
- 关注
原创 Third Maximum Number
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1: Input: [3, 2, 1] Ou
2017-03-10 01:16:15
324
原创 Pascal's Triangle II
Total Accepted: 105799 Total Submissions: 297504 Difficulty: Easy Contributors: Admin Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].Note:
2017-03-10 00:50:58
334
原创 Pascal's Triangle
Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]自己没有想到很好的解法,看了solution,被其代码惊呆了,
2017-03-09 21:41:25
299
原创 Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2, 3, 4].
2017-03-09 21:16:44
275
原创 Surrounded Regions
Given a 2D board containing ‘X’ and ‘O’ (the letter O), capture all regions surrounded by ‘X’.A region is captured by flipping all ‘O’s into ‘X’s in that surrounded region.For example, X X X X X O O
2017-03-09 15:22:03
268
原创 Number of Islands
Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume
2017-03-09 14:27:48
261
原创 Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely s
2017-03-09 11:38:28
223
原创 Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me
2017-03-07 20:06:36
298
原创 Search Insert Position
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 order.You may assume no duplicates in the array.Here
2017-03-07 00:38:14
212
原创 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le
2017-03-06 21:47:21
226
原创 Add Two Numbers
leetcode的第二道题目,自己先通过自己的笨办法写了一下,大致思路就是把两个listnode转换为真正的数,经过相加,取逆,再转换为Listnode输出。算法勉强通过,每次运行时间有一定的差异, 大致在150ms左右,先把自己的代码贴出来,再学习一下其他好的解法。class Solution(object): def addTwoNumbers(self, l1, l2):
2017-03-06 16:42:24
208
原创 PyLucene学习之三
Lucene分析器及统计词频分析分析(Analysis),在Lucene中指的是将域(Field)文本转换成最基本的索引表示单元—项(Term)的过程。语汇单元化过程(tokenization),从文本中提取的文本块称为语汇单元(token)。语汇单元与它的域名结合后,就形成了项(Term)。只有由分析器产生的语汇单元才能被搜索,例外情况是索引对应的域时使用Field.Inde
2016-03-07 15:26:33
884
原创 PyLucene学习之二
文档和域文档是Lucene索引和搜索的原子单位,文档为包含一个或多个域的容器,而域则依次包含”真正的“被索引内容。索引提取文本->创建对应Document实例->通过分析将域文本处理成大量语汇单元->将语汇单元加入段结构 使用倒排索引的数据结构进行存储,能够有效的利用磁盘空间,把文档中提取出的语汇单元作为查询关键字索引步骤1 首先创建Directory对象用于存放索引store=SimpleFSD
2016-02-03 11:24:24
1414
原创 PyLucene学习之一
简介Lucene是一款高性能的、可扩展的信息检索工具库。 信息检索是指文档搜索,文档内信息搜索或者文档相关的元数据搜索等操作。 Lucene只是搜索程序的核心索引和搜索模块搜索程序首先需要实现的功能是索引链, 分为以下几个步骤: 1. 检索原始内容 2. 根据原始内容来创建对应的文档 3. 对创建的文档进行索引Raw Content -> Acquire Content -> Build
2016-02-03 11:06:45
732
原创 卡尔曼滤波器学习之一最小二乘法
近期对卡尔曼滤波器很感兴趣,想趁着假期的时候好好学习一下。选择的教材是《Fundamentals of Kalman Filtering A Practical Approach, Third Edition》。本系列按照数据的章节顺序安排内容,本文的内容是书籍的第二章,最小二乘法。最小二乘法综述我们的目标是尽可能的逼近真实信号,通过处理采集来的被噪声污染的信号。主要分为两步:
2016-02-03 10:53:26
4532
1
原创 PyLucene安装与初试
安装尝试在Windows上安装,遇到各种各样的bug,遂放弃在Linux上安装,下载源码,解压缩后根据官网安装指南(http://lucene.apache.org/pylucene/install.html)进行安装在安装中遇到了如下的问题: 1. 依赖:java jdk, ant 2. 修改MakeFile文件时,环境变量在文件中修改会出问题,需要在terminal中export所有的
2016-02-03 10:46:20
3603
原创 Two Sum
Two Sum这道题是进入leetcode的第一道题目,大致的思路最开始就是暴力解法,将数组中的每两个数相加,然后和target相比,计算了下复杂度,大概在O(n2)。换个思路,用target减去当前的数,在从数组中查询是否存在这个数。但是没有想到hash的办法,导致其实复杂度还是在O(n2)。但也通过了测试,看了网上有很多种办法,可以逐一学习一下。主要的方法有两种: 1. 先排序然后用双指针向中
2016-01-18 17:35:25
422
原创 json encoder
在项目中需要将类转换成json的格式存储,考虑到比较简单的方式是继承json自带的JSONEncoder,修改其中的内容使其可以将类转换成我需要的json形式。在官网有找到如下内容:import jsonclass ComplexEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, com
2016-01-18 10:52:00
1198
原创 Python多进程(multiprocessing)一
目录目录简介Process 类进程间通信Queues进程间同步Markdown及扩展表格定义列表代码块脚注目录数学公式UML 图离线写博客浏览器兼容简介多进程相对于多线程可以更好的使用多核,避开GIL(Global Interpreter Lock)的影响。而且多进程引入了进程池的概念,可以更好的并行处理不同输入的数据。
2016-01-17 17:54:53
575
翻译 python积分scipy.integrate
python积分scipy.integratescipy.integration提供多种积分的工具,主要分为以下两类。对给出的函数公式积分:quad dblquad tplquad fixed_quad quadrature romberg对于采样数值进行积分:trapz cumtrapz simpz romb本文关注于对数值积分的trapz以及cumtrapz函数。 trapz
2015-07-30 10:38:03
26883
翻译 numpy学习之linspace
numpy.linspacenumpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)该函数返回一组具有相同间隔的数据/采样值,数据的间隔通过计算获得参数:start:序列的起始值stop:序列的终止值,除非endpoint被设置为False。当endpoint为True时,数据的间隔:(stop-s
2015-07-26 10:31:25
1995
原创 cookie与session
Cookie & Session无状态的Http协议Http协议是无状态的协议。不会一直连接着,就是客户端向服务器发出请求,然后服务器端回复,一旦数据交换完毕,客户端与服务器端的连接就会断开。再次交换数据就需要建立新的连接,意味着服务器端无法跟踪会话。而一个用户的所有请求都应该属于同一个会话。类似于用户A在超市购买的任何商品都应该放在A的购物车内,不论A什么时间购买都应该属于同一个会话,不能放入用户
2015-07-24 09:52:41
391
原创 Python 时间,日期,时间戳(一)
Python 时间,日期,时间戳(一)python time模块中的函数调用了运行平台中的C语言库,因此一些函数的语义和细节定义(例如epoch的起始以及支持的最大值等)是与平台相关的。Python time模块术语解释:epoch:时间起始点。在Unix系统,epoch是1970的1月1日的零时。time模块只能处理epoch以后的时间,同时对于未来的时间也有个限制点,该点是由所在平台的C语言
2015-07-23 16:56:18
1046
原创 Python中的变量、引用和作用域
Python中的变量、引用、拷贝和作用域可变对象 & 不可变对象在python中,对象分为两种:可变对象和不可变对象。不可变对象包括int,float,long,str,tuple等,可变对象包括list,set,dict等。这里说的不可变指的是值的不可变。对于不可变类型的变量,如果要更改变量,则会创建一个新值,把变量绑定到新值上,而旧值没有被引用就等待垃圾回收。可变类型数据对对象操作的时候,不需要
2015-07-23 09:32:17
2682
原创 概率论入门之一
概率论系列主要是记录学习MIT 的Introduction to Probability and Statistics 的学习笔记。按章节安排来分开我的博客内容。
2015-07-23 09:26:29
551
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人