
python
胡啦啦
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 · 2001 阅读 · 0 评论 -
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 · 267 阅读 · 0 评论 -
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 · 271 阅读 · 0 评论 -
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 · 278 阅读 · 0 评论 -
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 · 301 阅读 · 0 评论 -
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 · 230 阅读 · 0 评论 -
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 · 214 阅读 · 0 评论 -
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 · 337 阅读 · 0 评论 -
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 · 327 阅读 · 0 评论 -
Add Two Numbers
leetcode的第二道题目,自己先通过自己的笨办法写了一下,大致思路就是把两个listnode转换为真正的数,经过相加,取逆,再转换为Listnode输出。算法勉强通过,每次运行时间有一定的差异, 大致在150ms左右,先把自己的代码贴出来,再学习一下其他好的解法。class Solution(object): def addTwoNumbers(self, l1, l2):原创 2017-03-06 16:42:24 · 211 阅读 · 0 评论 -
Two Sum
Two Sum这道题是进入leetcode的第一道题目,大致的思路最开始就是暴力解法,将数组中的每两个数相加,然后和target相比,计算了下复杂度,大概在O(n2)。换个思路,用target减去当前的数,在从数组中查询是否存在这个数。但是没有想到hash的办法,导致其实复杂度还是在O(n2)。但也通过了测试,看了网上有很多种办法,可以逐一学习一下。主要的方法有两种: 1. 先排序然后用双指针向中原创 2016-01-18 17:35:25 · 424 阅读 · 0 评论 -
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 · 26949 阅读 · 0 评论 -
Python中的变量、引用和作用域
Python中的变量、引用、拷贝和作用域可变对象 & 不可变对象在python中,对象分为两种:可变对象和不可变对象。不可变对象包括int,float,long,str,tuple等,可变对象包括list,set,dict等。这里说的不可变指的是值的不可变。对于不可变类型的变量,如果要更改变量,则会创建一个新值,把变量绑定到新值上,而旧值没有被引用就等待垃圾回收。可变类型数据对对象操作的时候,不需要原创 2015-07-23 09:32:17 · 2685 阅读 · 0 评论 -
Python 时间,日期,时间戳(一)
Python 时间,日期,时间戳(一)python time模块中的函数调用了运行平台中的C语言库,因此一些函数的语义和细节定义(例如epoch的起始以及支持的最大值等)是与平台相关的。Python time模块术语解释:epoch:时间起始点。在Unix系统,epoch是1970的1月1日的零时。time模块只能处理epoch以后的时间,同时对于未来的时间也有个限制点,该点是由所在平台的C语言原创 2015-07-23 16:56:18 · 1052 阅读 · 0 评论 -
Python多进程(multiprocessing)一
目录目录简介Process 类进程间通信Queues进程间同步Markdown及扩展表格定义列表代码块脚注目录数学公式UML 图离线写博客浏览器兼容简介多进程相对于多线程可以更好的使用多核,避开GIL(Global Interpreter Lock)的影响。而且多进程引入了进程池的概念,可以更好的并行处理不同输入的数据。原创 2016-01-17 17:54:53 · 578 阅读 · 0 评论 -
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 · 1204 阅读 · 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 · 3608 阅读 · 0 评论 -
PyLucene学习之三
Lucene分析器及统计词频分析分析(Analysis),在Lucene中指的是将域(Field)文本转换成最基本的索引表示单元—项(Term)的过程。语汇单元化过程(tokenization),从文本中提取的文本块称为语汇单元(token)。语汇单元与它的域名结合后,就形成了项(Term)。只有由分析器产生的语汇单元才能被搜索,例外情况是索引对应的域时使用Field.Inde原创 2016-03-07 15:26:33 · 888 阅读 · 0 评论 -
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 · 225 阅读 · 0 评论 -
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 · 300 阅读 · 0 评论