mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
Merge pull request #283 from clobob/master
fix type error (except an int) in jumpmp_search line 7.
This commit is contained in:
commit
0a1b6ad4cf
|
@ -2,11 +2,11 @@ from __future__ import print_function
|
|||
import math
|
||||
def jump_search(arr, x):
|
||||
n = len(arr)
|
||||
step = math.floor(math.sqrt(n))
|
||||
step = int(math.floor(math.sqrt(n)))
|
||||
prev = 0
|
||||
while arr[min(step, n)-1] < x:
|
||||
prev = step
|
||||
step += math.floor(math.sqrt(n))
|
||||
step += int(math.floor(math.sqrt(n)))
|
||||
if prev >= n:
|
||||
return -1
|
||||
|
||||
|
@ -23,4 +23,4 @@ def jump_search(arr, x):
|
|||
arr = [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]
|
||||
x = 55
|
||||
index = jump_search(arr, x)
|
||||
print("\nNumber " + str(x) +" is at index " + str(index));
|
||||
print("\nNumber " + str(x) +" is at index " + str(index));
|
||||
|
|
Loading…
Reference in New Issue
Block a user