2 Star 10 Fork 2

国斌 / myleetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
InterpolationSearch.py 575 Bytes
一键复制 编辑 原始数据 按行查看 历史
Charies Gavin 提交于 2020-02-06 12:44 . 初始化 myleetcode 项目
"""
author: Charies Gavin
date: 11/8/19,4:55 PM
https:github.com/guobinhit
description: Interpolation Search
"""
# tips nums must be sorted
def interpolation_search(nums, left, right, target):
if left > right or target < nums[left] or target > nums[right]:
return -1
mid = left + (right - left) * (target - nums[left]) // (nums[right] - nums[left])
if target > nums[mid]:
interpolation_search(nums, mid + 1, right, target)
elif target < nums[mid]:
interpolation_search(nums, left, mid - 1, target)
else:
return mid
Java
1
https://gitee.com/guobinhit/myleetcode.git
git@gitee.com:guobinhit/myleetcode.git
guobinhit
myleetcode
myleetcode
master

搜索帮助