摘要: 文件结构- run.py- b-- __init__.pyrun.py 1 import logging 2 3 import b 4 5 log = logging.getLogger("") 6 7 tmp = logging.FileHandler('log.txt') 8 log.ad... 阅读全文
posted @ 2014-09-29 13:50 mess4u 阅读(503) 评论(0) 推荐(0) 编辑
摘要: 函数参数的顺序def hello(greeting, name): print greeting + name如果记不清函数的参数顺序,可以在调用时hello(greeting = "hey", name = "jude")这样的话可以在看到函数调用时就知道参数做什么的也可以在定义的地方设置默认值d... 阅读全文
posted @ 2014-09-10 14:52 mess4u 阅读(312) 评论(0) 推荐(0) 编辑
摘要: 在执行 import module 时 会从1 当前目录2 pythonpath(可以通过 os.sys.path 查看)3 python 安装目录b import 了 a, c import 了 b,c 中也会有定义test.py 1 __all__ = ['a', 'b'] 2 3 def a... 阅读全文
posted @ 2014-09-10 09:20 mess4u 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Code1 a = [1,2,2,3]2 b = [for item in a if item not in b]3 4 c = []5 for item in a:6 if item not in c:7 c.append(item)b -- [1,2,2,3]c -- [... 阅读全文
posted @ 2014-09-05 10:51 mess4u 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 描述:实现1 -- 求所有可能的值,O(N^2),超时了(因为超时没有跑所有的测试用例,所以不确定还有没有其他问题)代码: 1 def maxArea(self, height): 2 tmp = len(height) 3 if tmp == 0 or tm... 阅读全文
posted @ 2014-08-21 14:37 mess4u 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 描述:要求相邻数2进制差一位先获得n-1的列表表示小于 2^(n-1) 的符合要求的列表,加上最高位的加成 2^(n-1) 就是大于等于 2^(n-1) 的符合要求的列表,后者翻转一下就能够与前者连接上了代码: 1 class Solution: 2 # @return a list of ... 阅读全文
posted @ 2014-08-11 17:45 mess4u 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 描述:输出全排列代码: 1 class Solution: 2 # @param num, a list of integer 3 # @return a list of lists of integers 4 def doSth(self, num): 5 ... 阅读全文
posted @ 2014-08-11 15:42 mess4u 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 描述:使用了递归,有些计算是重复的,用了额外的空间,Version 1是m*nBonus:一共走了m+n步,例如 m = 2, n = 3 [#, @, @, #, @],所以抽象成数学问题,解是C(m + n, m)代码: 1 class Solution: 2 # @return an ... 阅读全文
posted @ 2014-08-11 15:32 mess4u 阅读(202) 评论(0) 推荐(0) 编辑
摘要: P28 复制 1 a = [1,2,3,[1,2]] 2 b = a 3 b is a # True 4 c = list[a] # shallow copy 5 c is a # False 6 c[3][0] = 100 7 a # [1,2,3,[100,2]] 8 import copy 9... 阅读全文
posted @ 2014-08-07 15:20 mess4u 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 语言:python 1 # state[0] = 1 to represent a queen 2 # state = (1,3,0,2) 3 # * Q * * 4 # * * * Q 5 # Q * * * 6 # * * Q * 7 def conflict(state, nextX): 8... 阅读全文
posted @ 2014-08-05 15:36 mess4u 阅读(193) 评论(0) 推荐(0) 编辑