algorithm's Issues
二分查找算法实现 一文作者不小心,有误
原谅:
也可以不用递归方法,而采用循环,如下:
def binarySearch(lst, value,low,high): #low,high是lst的查找范围
if high < low:
return -1
mid = (low + high)/2
if lst[mid] > value:
return binarySearch(lst, value, low, mid-1)
elif lst[mid] < value:
return binarySearch(lst, value, mid+1, high)
else:
return mid
最后应该是
return lst[mid]
另外 当 high< low 时 返回-1 ,对此不解。 应该返回None
Ivo Ricardo
HFBW 2SKL OVXD EZCT JJXF KMTS N5XE YUKE
哪错了? 齐老板
fib数列
def fib1(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib1(n-1) + fib1(n-2)
memo = {0:0, 1:1}
def fib2(n):
if not n in memo:
memo[n] = fib2(n-1)+fib2(n-2)
return memo[n]
第二种方法似乎不会在计算上有什么优势,求大于1的fib数列都需要全部计算一次。
数值转化
mid = (low + high)/2
,建议用int()转换成整型,不然会报错:
mid = int((low + high)/2)
sir?
dijkstra 算法 在机器上跑过没?明显有错误啊!对照这里,缩进错误
如果可以,希望大侠多点注释
>>> def odd_even(l):
... return [i for i in l if (~i&1)] + [j for j in l if (j&1)]
string_to_hump.md 里的python代码似乎可以写得更简单一些
比如这样:
#! /usr/bin/env python
print "Please input a name:"
snake_case = raw_input()
camelCase = []
for ch in snake_case.split("_"):
camelCase.append(ch.title())
print "".join(camelCase)
method 2 in quick_sort.md may have a syntax error
the statement is awesome but there are bugs in the code of method 2
def qsort(L):
return (qsort([y for y in L[1:] if y < L[0]]) +
L[:1] +
[y for y in L[1:] if y == L[0] + qsort([y for y in L[1:] if y > L[0]]) ) \
if len(L) > 1 else L
'[' does not appear in pairs.
maybe you need a ']' after if y == L[0]
in line 4.
index_search_whoosh.md 中,parse的问题
from whoosh.qparser import QueryParser
with ix.searcher() as searcher:
query = QueryParser("content",ix.schema).parse("second")
result = searcher.search(query)
results[0]
其中parse是否也可以先分词呢
查找字符串中出现最多的字符和个数:Ruby
str.split('').uniq.map {|x| [x, str.count(x)]}.sort{|a,b| b[1]<=>a[1]}[0]
str = "sdsdsddssssssdd"
str.split('').uniq.map {|x| [x, str.count(x)]}.sort{|a,b| b[1]<=>a[1]}[0]
# => ["s", 9]
操作二维整数数组里分数没有区分课程
目前的算法分数没有区分课程,那么给定课程的信息对比算法变成了冗余的。
如果要区分课程的话,用nameturple会不会更好一些?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.