![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
文章平均质量分 67
红金龙-时光
这个作者很懒,什么都没留下…
展开
-
leetcode 9 :Palindrome Number by pthon3
Runtime: 476 ms, faster than 29.19% of Python3 online submissions for Palindrome Number.显然 跟第七题一样首先按照题意负数没有回文数一个数的回文数必然等于自己class Solution: def isPalindrome(self, x): """ :ty...原创 2018-12-25 10:51:34 · 104 阅读 · 0 评论 -
leetcode 13 :roman-to-integer
思路很简单 如果 一个数 小于后一个数 那么取负Runtime: 180 ms, faster than 50.44% of Python3 online submissions for Roman to Integer.class Solution: def romanToInt(self, s): """ :type s: str :...原创 2018-12-25 11:24:13 · 110 阅读 · 0 评论 -
leetcode18: 4Sum by python3
超时:排序的结果需要用上 后面再修改class Solution: def fourSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[List[int]] """ len_num...原创 2018-12-25 12:32:34 · 137 阅读 · 0 评论 -
leetcode 35. Search Insert Position
Runtime: 56 ms, faster than 26.42% of Python3 online submissions for Search Insert Position.如果 target > list最后一个数 那就是插入到最后就是挨个比较class Solution: def searchInsert(self, nums, target): ...原创 2018-12-25 16:55:16 · 136 阅读 · 0 评论 -
leetcode 26: Remove Duplicates from Sorted Array
Runtime: 68 ms, faster than 71.33% of Python3 online submissions for Remove Duplicates from Sorted Array.数据结构里常见的题使用2个类指针,一个从1-n,一个只记录非重复的数据次数class Solution(object): def removeDuplicates(self,...原创 2018-12-25 17:41:42 · 127 阅读 · 0 评论 -
leetcode 27:Remove Element.
跟26题一个思路Runtime: 60 ms, faster than 23.48% of Python3 online submissions for Remove Element.class Solution: def removeElement(self, nums, val): """ :type nums: List[int] ...原创 2018-12-26 08:56:59 · 303 阅读 · 0 评论 -
leetcode 50: Pow(x, n)
Runtime: 76 ms, faster than 9.52% of Python3 online submissions for Pow(x, n).很简单class Solution: def myPow(self, x, n): """ :type x: float :type n: int :rtype: fl...原创 2018-12-26 09:04:51 · 313 阅读 · 0 评论 -
leetcode 43: Multiply Strings
Runtime: 64 ms, faster than 75.88% of Python3 online submissions for Multiply Strings.难不成这用其他语言很难???这个还中级难度。。。应该是有其他独特的方法吧class Solution: def multiply(self, num1, num2): """ :typ...原创 2018-12-26 09:08:53 · 358 阅读 · 0 评论 -
leetcode 58: Length of Last Word.
Runtime: 52 ms, faster than 29.03% of Python3 online submissions for Length of Last Word.class Solution: def lengthOfLastWord(self, s): """ :type s: str :rtype: int ...原创 2018-12-26 09:12:51 · 279 阅读 · 0 评论 -
leetcode 21:Merge Two Sorted Lists
Runtime: 68 ms, faster than 28.06% of Python3 online submissions for Merge Two Sorted Lists.由于对python指针不熟悉,参考了一下其他同学的写法这题就是标准的数据结构题目,学过数据结构的同学应该都见过类似的题目好像是 尾插法# Definition for singly-linked list....原创 2018-12-26 10:05:44 · 150 阅读 · 0 评论 -
leetcode 7 Reverse Integer
88ms : Your runtime beats 23.38 % of python3 submissionsclass Solution: def reverse(self, x): """ :type x: int :rtype: int """ y = abs(x) sum原创 2018-12-24 17:41:21 · 109 阅读 · 0 评论 -
leetcode 1. Two Sum
python3正常方式:双重循环6384 ms :Your runtime beats 7.14 % of python3 submissionsclass Solution: def twoSum(self, nums, target): """ :type nums: List[int] :type target: int ...原创 2018-12-24 16:52:37 · 115 阅读 · 0 评论 -
Linux终端没有GUI,如何使用matplotlib绘图
参考:Linux终端没有GUI,如何使用matplotlib绘图linux小白晋升记——QXcbConnection: Could not connect to displayimport matplotlib as mplmpl.use('Agg')import numpy as npimport matplotlib.pyplot as pltplt.figure(1) # ...转载 2019-01-03 18:27:22 · 1235 阅读 · 0 评论 -
Python爬虫第一步之获取网页源代码
“’ python #coding=utf-8 import urllibdef getHtml(url): page = urllib.urlopen(url) html = page.read() return htmlhtml = getHtml(“http://blog.sina.com.cn/“) “’# coding=utf-8PY文件当中是原创 2016-06-12 20:05:56 · 11064 阅读 · 0 评论 -
python爬虫之爬取网页
本文代码源自 Python爬虫抓取网页图片 希望读者点击原文进行阅览,本人使用Python2.7+Pycharm编译正常 本文采用Markdown格式编写# -*- coding: utf-8 -*-import urllibimport reimport timeimport os#显示下载进度def schedule(a,b,c): ''''' a:已经下载的数据块 b转载 2016-06-12 21:31:19 · 859 阅读 · 0 评论 -
Python 决策树 泰坦尼克号乘客是否生还决策模型
与网上的其他内容均一样import pandas as pdtitanic = pd.read_csv('http://biostat.mc.vanderbilt.edu/wiki/pub/Main/DataSets/titanic.txt')titanic.head() .dataframe thead tr:only-child th { text-align: rig原创 2017-12-20 22:51:11 · 978 阅读 · 0 评论 -
Python Apriori算法 载入数据修改 可以读取dataframe
def loadDataSet(dataSet): data1=list(map(lambda x:str(x) + '=',list(dataSet.columns))) + dataSet.applymap(str) train_data = np.array(data1)#np.ndarray() data1_list=train_data.tolist()...原创 2018-03-28 11:12:53 · 1163 阅读 · 0 评论 -
Python pandas 将dataframe变量取值频率(频数)小于一定比例的替换为空值
新建数据框from pandas import DataFrameimport numpy as npa=[1,1,2,2,4]#列表ab=[5,5,7,6,7]#列表bc={"a" : a, "b" : b}#将列表a,b转换成字典data=DataFrame(c)#将字典转换成为数据框print(data)函数块def GET_CR(X, p = 0.25...原创 2018-03-28 11:35:00 · 4319 阅读 · 0 评论 -
Python DataFrame 多条件筛选 使用&
DF6Out[42]: B C D0 1 B 10.7501 3 C 8.8752 2 T 58.0003 2 L 57.0004 3 Y 46.000DF6[(DF6.B>1) & (DF6.D > 10)]Out[45]: B C D2 2 T 58.03 2 L 5...原创 2018-08-10 18:28:30 · 51378 阅读 · 2 评论 -
pandas 筛选后对符合条件的数据另一个指标赋值
常见于我们对Y值进行赋值 eg:import pandas as pdfrom pandas import DataFrame ,SeriesA = Series(list('abc')).sample( 10, replace= True)B = Series(range(1,4)).sample(10, replace= True)#C = Series(range(1,1...原创 2018-08-07 16:36:38 · 18397 阅读 · 3 评论 -
leetcode 2:Add Two Numbers
Runtime: 208 ms, faster than 16.64% of Python3 online submissions for Add Two Numbers.原谅我,指针我已经不知道知道哪里去了。。。。# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# ...原创 2018-12-26 14:24:53 · 429 阅读 · 0 评论 -
leetcode 69:Sqrt(x)
Runtime: 80 ms, faster than 44.48% of Python3 online submissions for Sqrt(x).学习了一下,可以用牛顿法等方法求解参考:[LeetCode] Sqrt(x) 求平方根class Solution: def mySqrt(self, x): """ :type x: int ...原创 2018-12-26 17:27:13 · 434 阅读 · 0 评论 -
leetcode 66:Plus One.
Runtime: 52 ms, faster than 35.86% of Python3 online submissions for Plus One.思路:在list最前面加一个0然后倒着循环:L[i] + 1如果结果 = 10 ,那么 L[i] = 0; L[i-1] +1class Solution: def plusOne(self, digits): ...原创 2018-12-28 11:48:29 · 419 阅读 · 0 评论 -
leetcode 28:Implement strStr().
Runtime: 56 ms, faster than 36.86% of Python3 online submissions for Implement strStr().不知道这样子好不,直接用的分隔符分割数据其实在算法中是有这么一个匹配算法的,叫KMP算法,当然还有很多改进版的算法class Solution: def strStr(self, haystack, needl...原创 2018-12-26 10:56:14 · 158 阅读 · 0 评论