【python3.8】斐波拉契数列实现
Python3.8 实现 数列
2023-09-14 08:59:26 时间
import time def memoize(f): memo = {} def helper(x): if x not in memo: memo[x] = f(x) return memo[x] return helper @memoize def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-1) + fib(n-2) def fib_seq(n): res = [] if n > 0: res.extend(fib_seq(n-1)) res.append(fib(n)) return res # 耗时:7.870000000000099e-05 start_using_list = time.perf_counter() fib_seq(30) end_using_list = time.perf_counter() print(f'耗时:{end_using_list-start_using_list}') # def fib(n): # if n == 0: # return 0 # elif n == 1: # return 1 # else: # return fib(n-1) + fib(n-2) # # def fib_seq(n): # res = [] # if n > 0: # res.extend(fib_seq(n-1)) # res.append(fib(n)) # return res # # 耗时:1.2619506 # start_using_list = time.perf_counter() # fib_seq(30) # end_using_list = time.perf_counter() # print(f'耗时:{end_using_list-start_using_list}')
相关文章
- 通过淘宝镜像下载python3.8.3的安装包
- 通过淘宝镜像下载python3.8.3的安装包
- 【python3.8】斐波拉契数列实现
- Python3.8 标准库 —— The Python Standard Library
- Python3.8的新功能
- 走过岁月我才发现——云IDE真方便(Python3.8环境测试)
- 已解决(Python3.8异常)AttributeError: module ‘time‘ has no attribute ‘clock‘
- ubuntu安装python3.8
- docker运行python3.8
- python3.8 := and python3.7 dataclass
- 在linux里安装python3.8.3版本
- 升级centos7自带的Python2.7到Python3.8
- 快速安装jupyter for Python3.8版本(Windows7下的安装)
- centos7下离线安装TensorFlow2.2.0 For Python3.8(部署狂人的日记)
- CUDA+torch+vscode安装教程(python3.8)
- 解决python使用pip安装包时出现WARNING: Ignoring invalid distribution -ip (f:python3.8libsite-packages)的问题
- Python3.8安装Pygame教程