python
文章平均质量分 81
iKeepGoing
coder
展开
-
python趣味入门——写几个常玩的游戏
文档介绍利用python写“猜数字”,“猜词语”,“谁是卧底”这三个游戏,从而快速掌握python编程的入门知识,包括python语法/列表/元组/字典/流程控制/库函数等等。环境参数linux平台,python 3.4。需要在linux中把python 3.4编译一下,这样编写python程序时保存为.py格式的文件并添加执行权限再终端运行即可(原理跟shell脚本相同),非原创 2014-12-14 14:19:50 · 59846 阅读 · 7 评论 -
leetcode第6题——*ZigZag Conversion
题目The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA原创 2015-12-31 10:18:32 · 596 阅读 · 0 评论 -
leetcode第5题——**Longest Palindromic Substring
题目Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.思路题目是要求出字符原创 2015-12-30 11:30:08 · 605 阅读 · 0 评论 -
leetcode第4题——***Median of Two Sorted Arrays
题目There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).思路要求出两个有序数组(长度分别为原创 2015-12-29 09:52:15 · 649 阅读 · 0 评论 -
leetcode第3题——**Longest Substring Without Repeating Characters
题目Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3.原创 2015-12-19 22:56:33 · 1348 阅读 · 0 评论 -
leetcode第2题——**Add Two Numbers
题目You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as原创 2015-12-19 11:28:16 · 1277 阅读 · 0 评论 -
leetcode第1题——**Two Sum
题目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,原创 2015-12-19 10:36:13 · 720 阅读 · 0 评论 -
leetcode第23题——***Merge k Sorted Lists
题目Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路将数组中的k个有序链表归并成一个有序链表,并分析时间复杂度。该题可以在第22题-"merge two sorted lists"的基础上设计算法。一开始想到遍历数组的k-1原创 2016-03-01 23:11:32 · 842 阅读 · 0 评论 -
leetcode第24题——**Swap Nodes in Pairs
题目Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant原创 2016-03-03 09:47:19 · 1247 阅读 · 0 评论 -
leetcode第19题——*Remove Nth Node From End of List
题目Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the原创 2016-02-19 18:47:47 · 491 阅读 · 0 评论 -
python输出中文——如何在Windows控制台打印不乱码
文章介绍用Python在控制台打印中文如何不会乱码,一直是困扰很多Pythoner的问题,甚至很多Python老手也经常犯难。原因就在于从一般网页、数据库或文本外来数据源上抓取过来的内容,需要经过正确的编解码才可以正常输出,而Python的编解码机制比较复杂,没有深入思考的话经常遇到调试错误。这篇文章介绍了最常见的几种输出中文的情况,编译平台为Windows控制台,Python版本为2.7.9原创 2015-08-27 15:40:39 · 22570 阅读 · 0 评论 -
leetcode第20题——*Valid Parentheses
题目Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are原创 2016-02-27 11:45:43 · 978 阅读 · 0 评论 -
leetcode第22题——**Generate Parentheses
题目Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())原创 2016-02-29 09:55:52 · 801 阅读 · 0 评论 -
leetcode第21题——*Merge Two Sorted Lists
题目Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.思路把两个有序链表归并成一个有序链表。先用比较笨但很简洁的办法:遍历两个有序链表的节点,比较值原创 2016-02-28 10:09:15 · 1215 阅读 · 0 评论 -
递归和非递归方法实现斐波那契数列
介绍斐波那契数列(Fibonacci sequence),又称黄金分割数列、因数学家列昂纳多·斐波那契(Leonardoda Fibonacci[1] )以兔子繁殖为例子而引入,故又称为“兔子数列”,指的是这样一个数列:0、1、1、2、3、5、8、13、21、34、……在数学上,斐波纳契数列以如下被以递归的方法定义:F(0)=0,F(1)=1,F(n)=F(n-1)+F(n-2)(n≥2原创 2016-04-13 11:32:56 · 3296 阅读 · 0 评论 -
leetcode第7题——*Reverse Integer
题目Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points原创 2015-12-31 20:01:06 · 468 阅读 · 0 评论 -
leetcode第8题——*String to Integer (atoi)
题目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 inpu原创 2016-01-01 11:07:29 · 772 阅读 · 0 评论 -
python进阶——利用网页爬虫写天气预报采集器
在上一篇博文中,博主通过三个游戏程序讲述了python入门知识点击打开链接,现在再讲讲如何利用网页爬虫来写一个天气预报采集器,主要就是在中国天气网上爬取网页并过滤数据,得到需要的天气信息并打印出来。其实要感谢我同学小党,他向我展示了他写的天气预报程序,可以输入城市后显示当前城市的天气和气温。然后我再完善了一下,不仅可以查全国城市的天气情况,也可以查一个省份或直辖市的总体天气情况,如输入“广东”原创 2014-12-14 15:57:42 · 7540 阅读 · 2 评论 -
Python实现数据处理——每隔一段时间把数据写入excel文件中
文章介绍在上一篇博文中,我讲述了利用Python的selenium模块抓取动态数据的方法点击打开链接,那么这些抓到的数据如何处理呢?可以写入到excel表格中制成表格,进而画成统计图表直观显示出来。例如按照时间轴统计网站的在线人数,查看哪个时间段人最多,哪个时间段人最少,从而网站维护人员可以按照合适的时间分配资源,用户则可以选择合适的时间访问。要做到以上所述的数据处理,涉及到两个问题:原创 2015-09-30 17:36:26 · 18167 阅读 · 2 评论 -
Python抓取网页动态数据——selenium webdriver的使用
文章目的当我们使用Python爬取网页数据时,往往用的是urllib模块,通过调用urllib模块的urlopen(url)方法返回网页对象,并使用read()方法获得url的html内容,然后使用BeautifulSoup抓取某个标签内容,结合正则表达式过滤。但是,用urllib.urlopen(url).read()获取的只是网页的静态html内容,很多动态数据(比如网站访问人数、当前在线原创 2015-09-30 16:01:37 · 32526 阅读 · 1 评论 -
tesseract结合selenium快速搜索图片中的文字
大家有没有遇到过这样的问题:当我们看到有些图片中的文字(比如论文中的图片或公式等),想搜索一下,但苦于不能直接复制,只能手动敲入在百度的搜索框;或者碰到其他复制比较麻烦的地方,比如cmd窗口,也是如此.这样费时费力,还可能会输入错误。因此我尝试用python的验证码识别模块tesseract和自动化测试模块selenium写了个很简单的python程序,可以将想要搜索的文字截图下来保存在pyt原创 2016-01-04 15:55:35 · 2485 阅读 · 0 评论 -
leetcode第16题——**3Sum Closest
题目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原创 2016-01-22 14:58:46 · 619 阅读 · 0 评论 -
leetcode第17题——**Letter Combinations of a Phone Number
题目Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digi原创 2016-01-23 00:10:22 · 755 阅读 · 0 评论 -
leetcode第18题——**4Sum
题目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:Ele原创 2016-01-23 00:13:42 · 652 阅读 · 0 评论 -
leetcode第15题——**3Sum
题目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,原创 2016-01-20 00:31:54 · 1355 阅读 · 0 评论 -
leetcode第14题——*Longest Common Prefix
题目Write a function to find the longest common prefix string amongst an array of strings.思路寻找字符串数组中所有字符串的最长公共前缀,注意是所有字符串的公共前缀,比如数组['hello', 'hell', 'he']的最长公共前缀为'he'。显然如果存在空字符串则公共前缀为空字符串。可以先将第一个字原创 2016-01-07 22:29:09 · 751 阅读 · 0 评论 -
leetcode第13题——*Roman to Integer
题目Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路这道题是12题逆向思维,事实上比12题要简单一点。我们知道:罗马数字由五个字母组合而成,分别是I(1)、V(5)、X(10)、L(50)、C(100原创 2016-01-06 22:51:52 · 1388 阅读 · 0 评论 -
leetcode第12题——**Integer to Roman
题目Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思路题目要求把1-3999的整数转换为罗马数字。只要找出罗马数字各位上的规律,就可以很方便地解出了。个位上的罗马数字(1-9)为'I','II','II原创 2016-01-06 21:05:21 · 744 阅读 · 0 评论 -
leetcode第11题——**Container With Most Water
题目Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i,原创 2016-01-06 17:08:02 · 777 阅读 · 0 评论 -
leetcode第10题——***Regular Expression Matching
题目Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire原创 2016-01-05 16:07:08 · 2434 阅读 · 2 评论 -
leetcode第9题——*Palindrome Number
题目Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convert原创 2016-01-03 17:20:42 · 586 阅读 · 0 评论 -
算法基础——十种常用排序算法的Java及Python实现
概述八大排序算法不用多说了,程序员算法基础必须要掌握的,现在总结一下加深记忆。下图是这八大排序算法的分类、名称、时间空间复杂度,以及稳定性。代码以下是经典八大排序算法的Java及Python代码,都是基于经典算法书籍《算法导论》里的伪代码实现的,我在关键语句部分附上了注释。按照上图中的顺序分别介绍八大排序算法的实现,前面是Java,后面是Python。Java的排序函数写在原创 2016-04-01 14:58:46 · 1920 阅读 · 0 评论