- 博客(4)
- 收藏
- 关注
数组的最大子数和问题
数组的最大子数和问题就是 有一个数组a,求a中和最大的连续子序列。 下面是看了《编程之美》的五种解法,计算复杂度和空间复杂度递减 1 O(N^3) def maxsubsum(a): l = len(a) max = min(a) for i in range(l): for j in range(i, l): ...
2009-07-16 17:19:53
213
利用round函数的二分查找
二分查找是一种简单高效的搜索算法 不过前提必须为进行搜索的数组为有序的 一般情况下的实现方法中mid的取值为(low+high)/2的整数 但试想一下如果mid改为round值的话会不会提高搜索的效率呢 下面为一般情况的实现 def binary_search(a, t, debug=False): l = 0 h = len(a) while l ...
2009-07-14 09:42:16
155
原创 “C#静态变量的诡异与恶心”之我见
今天看到了一个帖子题目说是"C#静态变量的诡异与恶心 " 我也说说我的看法,看下面的C#代码 1. using System; 2. 3. namespace StaticTest 4. { 5. class A 6. { 7. public static int X; 8. ...
2009-01-01 22:50:16
352
原创 Groovy的Closure
Groovy中有几个挺奇怪的地方 this owner delegate 下面为例子 class Mother { int field = 1 int foo() { return 2 } Closure birth (param) { def local = 3 def closure = {caller -> [this, field, foo(), local, p...
2008-12-14 22:43:38
166
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人