自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(209)
  • 收藏
  • 关注

原创 Python之 @property 用法

@Property 可以理解为装饰器的作用将类方法转换为只读属性重新实现一个属性的setter和getter方法import tracebackclass Students(object): @property def score(self): return self._score @score.setter def score(self,value):

2017-09-05 07:08:19 358

原创 Python之 __slots__ 的用法

使用__slots__限定class实例 能添加的属性__slots__仅仅对当前的类实例起作用,对继承的子类不起作用。知识点:1、捕获异常最好使用traceback。2、MethodType作用是将方法绑定到类上,并不是将方法直接写在类中,而是在内存中创建一个link指向外部的方法,在创建实例时候link也会得到复制。import tracebackfrom types

2017-09-05 06:42:10 418

原创 python 模拟链表

class Node(): def __init__(self,value,next=None): self.value = value self.next = next def CreateList(n): if n<=0: return False if n == 1: return N

2017-09-04 21:21:09 305

原创 125. Valid Palindrome(回文)

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a

2017-09-04 08:27:06 280

原创 lambda匿名函数

简介:Python使用lambda来创建匿名函数。lambda的主题个表达式,函数体比def简单的多。lambda函数有自己的命名空间,且不能访问自有参数列表之外或全局命名空间里面的参数。虽然lambda函数看起来只有一行,确不等同于C或C++的内联函数,后者的目的是调用小函数时不占用栈内存从而增加运行效率。语法:Lambda函数的语法只包含一个语句,如下:lambda

2017-09-03 08:44:55 523

原创 Python 文件操作之Copy

用到的知识点:openreadlinewith open as f 迭代器class FileOperation(object): def __init__(self): print('Start Operate File...') def Copy(self,src,dst): print('srouce file location = ',src)

2017-09-02 07:25:07 441

原创 136. 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 e

2017-08-28 08:32:07 142

原创 190. Reverse Bits

Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010

2017-08-28 07:53:05 164

原创 191. Number of 1 Bits

Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000

2017-08-26 07:09:17 125

原创 70. Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a posi

2017-08-26 06:49:32 146

原创 88. Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add

2017-08-25 22:55:52 200

原创 用栈实现队列的push、top和pop

Python中的list 已经自带append、pop、reverse、remove等方法class Solution(object): def push(self,li,data): li.append(data) return li def top(self,li): if len(li) == 0: return 'Empty Queue'

2017-08-25 08:29:42 2957

原创 创建二维矩阵并矩阵求和再转换

给定矩阵A,令矩阵B里每个元素B[i][j]的值等于A[0][0]到A[i][j]子矩阵元素的和class Solution(object): def CreateAMatrix(self,m,n): li_2d = [i for i in range(m)] print(li_2d) for i in range(m): li_2d[i] = [j f

2017-08-25 08:25:59 387

原创 54. Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]

2017-08-24 17:17:10 176

原创 Python 切片 和 数组推导

Python一些常用小技巧:li = list(range(10))print('li=',li)print('li[2:8]=',li[2:8])print('li[::-1]',li[::-1])li = [i*2 for i in range(10)]print('li = ',li)li_2d = [ [0] * 3] *3li_2d = [ [0] * 3 fo

2017-08-23 20:58:30 188

原创 344. Reverse String

字符串翻转Write a function that takes a string as input and returns the string reversed.Example1:Given s = "I love China!!", return = "!!anihC evol I"class Solution(object): def swap(self,s

2017-08-23 08:15:04 193

原创 204. Count Primes

Description:Count the number of prime numbers less than a non-negative number, n.求N以内的素数个数:1、方法一(超时做法):class Solution(object): def countPrimes(self, n): count = 0 result =

2017-08-23 06:19:47 227

原创 69. Sqrt(x)

Implement int sqrt(int x).Compute and return the square root of x. 翻译:开根号方法一:牛顿迭代法class Solution(object): def mySqrt(self, x): pre = 0 cur = x whil

2017-08-19 16:45:53 203

原创 67. Add Binary

Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".翻译:字符串二进制相加class Solution(object): def addBinary(self, a, b): list

2017-08-19 15:17:35 162

原创 66. Plus One

Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digi

2017-08-19 14:27:41 180

原创 58. Length of Last Word

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is

2017-08-19 11:46:17 137

原创 53. Maximum Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] 

2017-08-19 11:21:37 172

原创 Python 中空字符串用于条件表达式的方法

import strings = ''if s is None: print('\'\' == None')else: print('\'\' != None')if not s: print('\'\' == False')else: print('\'\' != False')if s == False: print('Can use \'\' == Fal

2017-08-17 06:56:31 5903

原创 38. Count and Say

The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read

2017-08-16 23:15:19 139

原创 35. 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.

2017-08-16 22:19:08 137

原创 ubuntu 12.04 安装python3.5

环境:Ubuntu 12.04  + 自带的Python2.7目标:安装python3.5 1、查看当前Python版本  -----> 2.7.32、添加PPA,也就是“Personal Package Archives(个人软件包档案)   --->  sudo add-apt-repository ppa:fkrull/deadsnakes3、软件包升级

2017-08-15 08:34:10 3978 1

原创 28. Implement strStr()

Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.翻译:手动实现strstr(字符串模式匹配 ---> KMP --->寻找next数组)方法一:暴力求解,时间复杂度(O(mn)

2017-08-14 07:43:15 136

原创 27. Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The

2017-08-13 23:04:25 189

原创 26. Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with

2017-08-13 20:25:54 125

原创 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 all va

2017-08-12 23:29:30 109

原创 14. Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.Trick:利用排序,只比较第一个和最后一个字符串即可class Solution(object): def longestCommonPrefix(self, strs): if strs ==

2017-08-12 07:53:58 183

原创 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 convertin

2017-08-11 07:59:01 127

原创 不重复数字求和

class Demo: def AddDiffSum(self,input): result = 0 store = [] for i in input: if store.count(i) == 0: store.append(i) for j in store: result += j return resu

2017-08-10 08:23:32 650

原创 7.Reverse Integer

Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Note:The input is assumed to be a 32-bit signed integer. Your function s

2017-08-10 08:07:23 207

原创 1. Two Sum

Given 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 have exactly one solution, and you may not use the sam

2017-08-09 08:29:48 246

原创 Python 2.7.3 AttributeError: 'module' object has no attribute 'urlopen'

在使用下面语句时候出现from urllib import urlopenwebpage = urlopen('http://www.python.org')AttributeError: 'module' object has no attribute 'urlopen'我是ubuntu 12.04 + 自带Python 2,7.3一开始以为是什么Python和Pytho

2017-08-07 08:00:50 3737

翻译 Python GUI程序之wxPython 小程序

本篇文章来自于《Python基础教程》12章wxPython 是一个越来越受欢迎的工具,它拥有成熟且特性丰富的包,下面我们来学习一个wxPython的例子。Demo:小型文本编辑器1、允许打开给定文件名的文本文件2、允许编辑文本文件3、允许保存文本文件4、允许退出程序Ps:相关的函数大家可以自行百度查看,都有详细的用法说明import wxdef load(eve

2017-08-05 09:30:27 849

原创 Python GUI 使用之wxpython的安装

1、环境安装:个人环境:ubuntu 12.04执行:apt-cache search wxpython 查看是否已经内嵌wxpython相关信息2、执行sudo apt-get install python-wxtools进行安装

2017-08-05 09:24:03 228

原创 根据输入成绩显示相应的级别

class Demo: def rhomb(self,input): result = '' input = input.strip() try: num = float(input) if num100: result = input + '-->' + 'Error number' elif num<60:

2017-08-05 09:19:29 1275

原创 求正整数的x,y的最小公倍数

class Demo: def gcd(self,x,y): if x<=0 or y<=0: return None if x>=y: max_value = x min_value = y else: max_value = y min_value = x while(max_value % mi

2017-08-04 06:33:43 716

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除