yidao620c / core-algorithm Goto Github PK
View Code? Open in Web Editor NEW算法集锦的python实现
算法集锦的python实现
def isLeapYear(year):
# return (not year % 4 and year % 100) or (not year % 400)
return (not (year % 4 and year % 100)) or (not year % 400)
def __quickSubSort(seq, p, r):
"""递归版本的"""
global num
num += 1
print(num)
if p < r:
# q = __partition(seq, p, r)
q = __randPartitions(seq, p, r)
__quickSubSort(seq, p, q - 1)
__quickSubSort(seq, q + 1, r)
def __quickSubSortTail(seq, p, r):
"""循环版本,模拟尾递归,可以大大减少递归栈深度,而且时间复杂度不高"""
global num
num += 1
print(num)
while p < r:
q = __randPartitions(seq, p, r)
# q = __partition(seq, p, r)
if q - r < r - q:
__quickSubSortTail(seq, p, q - 1)
else:
__quickSubSortTail(seq, q+1, r)
r = q - 1
我对比了下这两个函数的num值,发现你底下的这个版本递归深度是大于上面的递归版本的啊?是我理解错了吗?尤其是你__randPartitions版本的整整递归了几百次?是不是我测试错了?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.