最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python寻找局部最高点如何实现 Python寻找局部最高点实现代码
时间:2019-12-05 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Python寻找局部最高点实现代码,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
具体代码如下:
# 寻找局部最高点 # 输入input: 含有最高点高度的列表 # 输出output: 返回最高点的位置 # 时间复杂度: O(log(n)) def findHighSpot(input): iLen = len(input) mid = iLen//2 - 1 # Python中'/'为小数除法,'//'为地板除 if input[mid-1] <= input[mid] >= input[mid+1]: return str(mid+1) # 默认返回最高点到第一个点之间的距离 elif input[mid-1] > input[mid]: return findHighSpot(input[:mid//2]) else: return 'mid+'+findHighSpot(input[mid//2:]) # 返回最高点距离中间点的距离 if __name__ == '__main__': input = [1, 2, 6, 5, 3, 7, 4] output = findHighSpot(input) print('output:', output) # output: 3
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27