python
九日火
这个作者很懒,什么都没留下…
展开
-
python基础练习1-25
1.有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?for i in range(1,5): for j in range(1,5): for k in range(1,5): if( i != k ) and (i != j) and (j != k): print (i,j,k...原创 2018-10-02 14:53:26 · 1159 阅读 · 0 评论 -
python数组双指针算法
1.求和问题(LeetCode 2sum & 3sum & 4sum)1 Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would ...原创 2018-12-09 15:55:18 · 1046 阅读 · 0 评论 -
数据结构(某些题) python
题目:二维数组中,每行从左到右递增,每列从上到下递增,给出一个数,判断它是否在数组中def find_integer(matrix, num): if not matrix: return False rows, cosl = len(matrix), len(matrix[0]) row, col = rows-1, 0 while row&...原创 2018-12-30 11:16:30 · 165 阅读 · 0 评论 -
高质量代码(整理) python
题目:求整数次方def power(base, exponent): if equal_zero(base) and exponent < 0: raise ZeroDivisionError ret = power_value(base, abs(exponent)) if exponent < 0: return 1.0...原创 2018-12-30 11:48:16 · 386 阅读 · 0 评论 -
解决思路 python
题目:二叉树镜像def mirror_pre(root): ret=[] def travelsal(root): if root: ret.append(root.val) travelsal(root.right) travelsal(root.left) travelsal(...原创 2018-12-30 14:55:49 · 146 阅读 · 0 评论 -
优化时间和空间 python
题目:丑数def get_ugly(n): ugly=[1] t2, t3, t5=0, 0, 0 a=1 while a<n: minum=min(ugly[t2]*2, ugly[t3]*3, ugly[t5]*5) ugly.append(minum) while ugly[t2]*2<=min...原创 2018-12-31 20:26:34 · 168 阅读 · 0 评论 -
贷款自动审批模型
这个案例的背景:金融领域,申请贷款的人很多,可能银行每天要面对很多贷款申请,其中可能有很多不具备贷款资格的申请,为了缓解审批人员的工作量,可以根据申请人的一些资料,做一个模型自动过滤那些不具备贷款资格申请表。import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport matplotlib.imag...原创 2019-01-26 15:12:27 · 1688 阅读 · 0 评论 -
python 高级
1.Python中类方法、类实例方法、静态方法有何区别?类方法: 是类对象的方法,在定义时需要在上方使用 @classmethod 进行装饰,形参为cls,表示类对象,类对象和实例对象都可调用类实例方法: 是类实例化对象的方法,只有实例对象可以调用,形参为self,指代对象本身;静态方法: 是一个任意函数,在其上方使用 @staticmethod 进行装饰,可以用对象直接调用,静态方法...原创 2019-03-15 10:27:25 · 138 阅读 · 0 评论 -
python --某些题目
1.数组中出现次数超过一半的数字def more_than_half(alist): n=len(alist) if n==0: return res=alist[0] count=1 for i in range(1, n): if count==0: res=n[i] count=1...原创 2019-03-15 10:27:39 · 807 阅读 · 0 评论 -
python 一些内容
模块与包1.输入日期,判断这一天是这一年的第几天def year_of_year(): year = input("year: ") month = input("month: ") day = input("day: ") date1 = datetime.date(year = int(year), month=int(month), day = in...原创 2019-03-13 15:37:03 · 196 阅读 · 0 评论 -
python自然语言处理 第一章答案
1. 尝试使用Python解释器作为一个计算器,输入表达式,如:12/(4+1)12/42. 26 个字母可以组成 26 的 10 次方或者 26**10个 10 字母长的字符串。 也就是 141167095653376L(结尾处的 L 只是表示这是 Python 长数字格式)。100 个字母长度的字符串可能有多少个?26**1003.Python乘法运算可应用于链表。当你输入...原创 2019-03-23 16:07:25 · 837 阅读 · 0 评论 -
k8s基础
查看所有集群节点是否在运行kubectl get nodes查看更多的信息kubectl describe node ****可显示输出节点的状态、cpu、内存数据、系统信息以及运行容器的节点等。k8s部署应用程序通过:kubectl run的命令。例如:kubectl run kubia --image=luksa/kubia(指定要运行的容器镜像) --port=8080(监听...原创 2019-07-01 20:52:09 · 75 阅读 · 0 评论 -
卷
卷k8s是pod的一个组成部分,因此像容器一样在pod里定义了。同时卷被定义为pod的一部分和pod共享生命周期原创 2019-07-03 14:02:31 · 105 阅读 · 0 评论 -
k8s基础归结
查看所有集群节点是否在运行:kubectl get nodes查看更多的信息:kubectl describe node ****可显示输出节点的状态、cpu、内存数据、系统信息以及运行容器的节点等。k8s部署应用程序通过:kubectl run的命令。例如:kubectl run kubia --image=luksa/kubia(指定要运行的容器镜像)--port=8080(...原创 2019-06-28 00:09:13 · 152 阅读 · 0 评论 -
python数据结构之栈和队列
1.功能实现之前文章有,可以点开看看栈队列2.应用(1)括号匹配及后缀表达式class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ stack = [] d = ["()...原创 2018-12-09 14:17:12 · 160 阅读 · 0 评论 -
python数据结构之链表
1.功能实现链表(Linked list)是一种常见的基础数据结构,是一种线性表,但是并不会按线性的顺序存储数据,而是在每一个节点里存到下一个节点的指针(Pointer)。由于不必须按顺序存储,链表在插入的时候可以达到O(1)的复杂度,比另一种线性表顺序表快得多,但是查找一个节点或者访问特定编号的节点则需要O(n)的时间,而顺序表相应的时间复杂度分别是O(logn)和O(1)。特点:使用链...原创 2018-12-09 13:14:12 · 342 阅读 · 0 评论 -
数据结构与算法 部分题目(字符串)
1.求数组中两个字符串的最小距离题目:给定一个数组 strs,其中的数据都是字符串,给定两个字符串 str1,str2。如果这两个字符串都在 strs数组中,就返回它们之间的最小距离;如果其中任何一个不在里面,则返回 -1;如果两个字符串相等,则返回 0。例如:给定[‘*’,’3’,’*’,’5’,’10’,’9’,’7’,’1’,’*’],再给定两个字符串’* ‘和’9’,通过函数求得返...原创 2018-12-09 00:07:26 · 645 阅读 · 0 评论 -
python基础练习25-39
26.求100之内的素数。for i in range(2,101): for j in range(2,i): if i % j==0: break else: print(i)27.对10个数进行排序。这里用的是冒泡法if __name__ == "__main__": N = 10 # i...原创 2018-10-03 00:47:18 · 387 阅读 · 0 评论 -
leetcode简单(181-200)python
762. Prime Number of Set Bits in Binary Representation(e-181)Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary r...原创 2018-10-22 14:41:22 · 474 阅读 · 0 评论 -
leetcode中等.数组(1-20)python
15. 3Sum(m-1)Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.class Solution(object...原创 2018-10-28 14:03:21 · 465 阅读 · 0 评论 -
leetcode简单(201-220)python
852. Peak Index in a Mountain Array(e-201)Let's call an array A a mountain if the following properties hold:A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] ...原创 2018-10-24 11:17:00 · 581 阅读 · 0 评论 -
python 排序
数据结构常见排序性能比较插入排序直接插入排序的核心思想就是:将数组中的所有元素依次跟前面已经排好的元素相比较,如果选择的元素比已排序的元素小,则交换,直到全部元素都比较过。因此,从上面的描述中我们可以发现,直接插入排序可以用两个循环完成:第一层循环:遍历待比较的所有数组元素第二层循环:将本轮选择的元素(选定)与已经排好序的元素(ordered)相比较。如果:选择&g...原创 2018-10-27 12:22:11 · 224 阅读 · 0 评论 -
四道面试遇到的题(简单,大神莫喷)
1.二分法,查找第一个出错的文件(leetcode有原题)def find_first(n): left=1, right=n while True: mid=(left+right)/2 if isBadversion(mid): if mid==1 or not isBadversion(mid-1): ...原创 2018-11-06 10:05:04 · 101 阅读 · 0 评论 -
leetcode中等.数组(21-40)python
80. Remove Duplicates from Sorted Array II(m-21)Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.Do not allocate extr...原创 2018-11-04 15:15:25 · 194 阅读 · 0 评论 -
python数据结构的表现
链表1)含义:链表(Linked list)是一种常见的基础数据结构,是一种线性表,但是并不会按线性的顺序存储数据,而是在每一个节点里存到下一个节点的指针(Pointer)。由于不必须按顺序存储,链表在插入的时候可以达到O(1)的复杂度,比另一种线性表顺序表快得多,但是查找一个节点或者访问特定编号的节点则需要O(n)的时间,而顺序表相应的时间复杂度分别是O(logn)和O(1)2)特点:使...原创 2018-11-05 10:33:26 · 113 阅读 · 0 评论 -
python实现栈(stack)
栈具有独特特征last in first out(LIFO),栈的实现有以下部分stack()栈的创立 push(item)推顶 pop()弹出顶 peek()返回顶 is_empty()顶为空 size()返回栈的个数代码如下class stack(object): #创立容器 def __init__(self): self.__list=...原创 2018-11-24 21:43:59 · 275 阅读 · 0 评论 -
python实现队列(queue)
队列队列是一种先进先出的数据结构,主要操作包括入队,出队。入队的元素加入到对尾,从队头取出出队的元素。这里用列表简单模拟队列,其实现如下:queue() is_empty() size() enqueue() dequeue()代码如下:class queue(self): #创立容器 def __init__(self): self.__l...原创 2018-11-24 21:58:08 · 1823 阅读 · 1 评论 -
python实现链表
链表链表分为单向链表和双向链表,这里给出双向链表的实现class Node(object): def __init__(self, element): self.element=element self.prev=None self.next=None def get_element(self): ...原创 2018-11-24 22:14:18 · 182 阅读 · 0 评论 -
二叉树及遍历(python)
python数据结构–二叉树二叉树是每个节点最多有两个子树的树结构。通常子树被称作“左子树”(left subtree)和“右子树”(right subtree)二叉树的性质(特性)性质1: 在二叉树的第i层上至多有2(i−1)2(i−1)个结点(i>0)性质2: 深度为k的二叉树至多有2(k−1)2(k−1)个结点(k>0)性质3: 对于任意一棵二叉树,如果其叶结...转载 2018-11-25 00:09:04 · 84 阅读 · 0 评论 -
python----多线程
单线程顾名思义,可以理解为把一堆事情排在一起,一件一件去做,例子如下:比如我们回到家里,先写作业,在看书或者玩游戏娱乐一下。from time import ctime, sleepdef homework(): for i in range(3): print("i am doing homework.{}".format(ctime())) ...原创 2018-12-04 19:00:07 · 84 阅读 · 0 评论 -
pod
将服务暴露给外部服务器以下几种方法可以实现外部访问服务:1.将服务类型设置为NodePort每个集群节点都会在节点上打开一个端口,对于NodePort服务,每个集群节点在节点本身上打开一个端口,并将在该端口上接收到的流量重定向到基础服务。该服务在内部集群ip和端口上才能访问,也可以通过节点上专用端口访问。这种方法类似于常规的服务,但是不仅可以通过服务部分的内部集群IP访问NodePort服务...原创 2019-06-30 22:58:24 · 172 阅读 · 0 评论