会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
mess4u
新随笔
联系
订阅
管理
上一页
1
2
3
4
下一页
2014年8月1日
#Leet Code# Populating Next Right Pointers in Each Node II
摘要: 描述:注意需要先self.connect(right)再self.connect(left),否则会有case通不过,原因是左边递归执行时依赖与右边的next已经建立,而先执行connect(left)的话右边还没有完成关系的建立。代码: 1 class Solution: 2 # @par...
阅读全文
posted @ 2014-08-01 17:10 mess4u
阅读(159)
评论(0)
推荐(0)
2014年7月29日
#Leet Code# Sqrt
摘要: 描述:log(n)代码: 1 class Solution: 2 # @param x, an integer 3 # @return an integer 4 def getVal(self, begin, end, x): 5 if end == begi...
阅读全文
posted @ 2014-07-29 18:34 mess4u
阅读(138)
评论(0)
推荐(0)
#Leet Code# Best Time to Buy and Sell Stock
摘要: 描述:数组 A,对于 i max_minus:17 max_minus = tmp18 19 return max_minus动态规划:设dp[i]是[0,1,2...i]区间的最大利润,则该问题的一维动态规划方程如下dp[i+1] = ma...
阅读全文
posted @ 2014-07-29 14:38 mess4u
阅读(159)
评论(0)
推荐(0)
#Leet Code# Convert Sorted Array to Binary Search Tree
摘要: 描述:递归代码: 1 class Solution: 2 # @param num, a list of integers 3 # @return a tree node 4 def sortedArrayToBST(self, num): 5 if len(...
阅读全文
posted @ 2014-07-29 13:54 mess4u
阅读(96)
评论(0)
推荐(0)
2014年7月25日
#Leet Code# Evaluate Reverse Polish Notation
摘要: 描述:计算逆波兰表达法的结果Sample: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6使用stack实现: 1 def is_op(c): 2 ...
阅读全文
posted @ 2014-07-25 16:48 mess4u
阅读(126)
评论(0)
推荐(0)
重构技巧 引入Null对象
摘要: 描述:有两个类,学生类和导师类,学生的导师类可能不存在,因此在获取学生导师名字等信息时都要先判断导师名字是否为空。重构后通过一个空导师类来处理导师为空的相应逻辑。Before 1 # introduce null object 2 3 class Master: 4 def __init_...
阅读全文
posted @ 2014-07-25 10:03 mess4u
阅读(983)
评论(0)
推荐(0)
2014年7月18日
python yield
摘要: 描述:遍历数据,数据为数字或者由数字填充的列表不使用生成器1 data = [[1, 2], [3, 2], [5]]2 3 for lst in data:4 for item in lst:5 print item使用生成器1 data = [[1, 2], [3, 2]...
阅读全文
posted @ 2014-07-18 14:13 mess4u
阅读(183)
评论(0)
推荐(0)
2014年7月17日
todo
摘要: 递归描述逻辑循环描述处理方法
阅读全文
posted @ 2014-07-17 22:33 mess4u
阅读(110)
评论(0)
推荐(0)
Python 函数式编程学习
摘要: 描述:通过将函数作为参数,使得功能类似的函数实现可以整合到同一个函数。Before 1 def getAdd(lst): 2 result = 0 3 for item in lst: 4 result += item 5 return result 6 7...
阅读全文
posted @ 2014-07-17 16:55 mess4u
阅读(137)
评论(0)
推荐(0)
Python 修饰器
摘要: 描述:对于函数foo,使用修饰器修饰,在执行foo函数的同时统计执行时间。这样其他函数都可以使用此修饰器得到运行时间。(有返回值和没有返回值的函数要用不同的修饰器似乎)(对于有返回值的函数,不确定用result存储实际函数执行结果再最终返回的方法是不是恰当) 1 import time 2 3 d...
阅读全文
posted @ 2014-07-17 16:14 mess4u
阅读(4395)
评论(0)
推荐(1)
上一页
1
2
3
4
下一页
公告