![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
文章平均质量分 62
普通网友
这个作者很懒,什么都没留下…
展开
-
命令行安装的python包不被pycharm识别
参考链接:https://www.zhihu.com/question/373781465/answer/1034511974命令行装了个MySQLdb,但是PyCharm似乎不识别。去file->setting->interpreter看看,发现project下有这个包:根据知乎大佬指引,需要修改下项目配置文件。打开venv下的pyvenv.cfg文件...原创 2020-05-03 10:46:10 · 685 阅读 · 1 评论 -
LeetCode 23 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个有序链表。最直接的想法先合并两条链表,然后再与第三条链表进行合并,那么时间复杂度是o(2n+3n……kn)=o(nk²)另一种想法是借鉴归并排序的思想,两两合并。T(n)=2T(n原创 2017-07-01 12:19:05 · 197 阅读 · 0 评论 -
LeetCode 401 Binary Watch
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant bit o原创 2017-07-01 12:15:09 · 249 阅读 · 0 评论 -
LeetCode 532 K-diff Pairs in an Array
Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in原创 2018-01-23 14:38:58 · 172 阅读 · 0 评论 -
LeetCode 122 Best Time to Buy and Sell Stock II
这个题和Best Time to Buy and Sell Stock 是有关的。先看下Best Time to Buy and Sell Stock II:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitt原创 2018-01-23 14:56:35 · 126 阅读 · 0 评论 -
LeetCode 718 Maximum Length of Repeated Subarray
Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation: The repeated sub原创 2018-01-28 23:32:54 · 211 阅读 · 0 评论 -
LeetCode 667 Beautiful Arrangement II
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3,原创 2018-01-21 00:05:38 · 181 阅读 · 0 评论 -
LeetCode 621 Task Scheduler
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could b...原创 2018-02-15 10:08:10 · 170 阅读 · 0 评论 -
LeetCode 689 Maximum Sum of 3 Non-Overlapping Subarrays
In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum.Each subarray will be of size k, and we want to maximize the sum of all 3*k entries.Return the result ...原创 2018-02-15 10:24:21 · 290 阅读 · 0 评论 -
LeetCode 153 Find Minimum in Rotated Sorted Array
Suppose an array sorted in ascending order 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 exis...原创 2018-02-15 11:23:17 · 149 阅读 · 0 评论 -
LeetCode 201 Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.这个题开始想了想,以为直接loop就行了,但是又一想好歹是个中等难度,有这么简单?管他呢就简单loop。果然==Time Limit Exceeded。那有什么骚操作呢?就参考了别人的解法。有这么一个思路。说结果原创 2017-07-02 10:17:22 · 175 阅读 · 0 评论 -
LeetCode 541 Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of th原创 2018-01-14 17:08:10 · 205 阅读 · 0 评论 -
Python基础教程(5)条件、循环和其他语句
for遍历字典:d={'x':1,'y':2,'z':3}for k,v in d.items(): print k,v并行迭代:a=[1,2,3]b=[4,5,6]for x,y in zip(a,b): print (x,y)zip是把list压缩到一起enumerate。对于一个可迭代的(iterable)/可遍历的对象(如列表、字符串),enumerate将其组成一个索引序列原创 2017-10-17 22:17:25 · 256 阅读 · 0 评论 -
Python基础教程(6)抽象
文档化函数:def f(): 'print hello' print "hello"print f.__doc__原创 2017-10-17 22:48:00 · 209 阅读 · 0 评论 -
Python基础教程(1)
python3普通除法:1/2=0.5(python2 是0)整除:1//2=0十六进制表示:0xAf(175)八进制表示:0o10(0o开头,十进制的8)获取输入:x=input("x:")raw_inpurt()#string四舍五入:roundround的坑:python2中round(0.5)=1,python3中round(0.5)=0.p原创 2017-10-16 21:19:43 · 603 阅读 · 0 评论 -
Python基础教程(3)字符串
字符串不可变,因此不可分片赋值转换说明符%:>>> a='a%sb'>>> a%'b''abb'>>> find:子串查找:>>> a='fdfadsafd'>>> a.find('fd')0>>> 连接序列中的元素:join:>>> a=['1','2','3']>>> '.'.join(a)'1.2.3'#必须是str不能是int替换单个字符 translate原创 2017-10-16 22:57:31 · 485 阅读 · 0 评论 -
Python基础教程(2)列表和元组
列表可修改,元组不可修改,因此列表不可做字典的键序列(列表和元组)、映射(字典)都属于容器通用序列操作:索引,分片,加,乘,判断元素是否属于序列等删除>>> name=['a','b','b']>>> del name[2]>>> name['a', 'b']分片:>>> list("naive")['n', 'a', 'i', 'v', 'e']append:在列表尾部加元素co原创 2017-10-16 21:46:01 · 193 阅读 · 0 评论 -
记一次坑爹的爬虫经历
需求:有这样一个网站:http://www.5er0.com/.网站可以搜索有关电影电视剧有关的信息或者下载链接。现在要输入一个video name,爬到其下载链接。首先我们打开网站首页:看到有个搜索框,我们尝试输入战狼并点击搜索,得到结果如下:既然爬虫我们就要看一下数据是如何请求的,回到首页,审查元素查看搜索框的元素:看到这是一个post表单。再看搜索结果页...原创 2017-11-06 18:40:02 · 3873 阅读 · 2 评论 -
堆排序(Python)
堆排序的Python实现原创 2017-12-11 11:50:39 · 337 阅读 · 0 评论 -
LeetCode 169 Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2018-01-21 16:36:30 · 176 阅读 · 0 评论 -
LeetCode 448 Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-12-23 22:45:14 · 132 阅读 · 0 评论 -
Python基础教程(4)字典
关键字方式创建字典d=dict(name='tom',age=20)d{'age': 20, 'name': 'tom'}key必须是不可变类型,数字字符串元组字典格式化字符串d={'a':123}print '%(a)d'%d123copy:返回一个相同键值对的新字典,但是这个是浅拷贝。如果对副本值进行替换,原字典不受影响:a=dict(name='jzm',age=90)b=a.co原创 2017-10-17 20:49:55 · 290 阅读 · 0 评论