mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-05 21:04:28 +08:00
fix(curriculum): editable regions in workshop binary search (#67780)
This commit is contained in:
parent
5828f78de5
commit
e951b72d72
@ -31,8 +31,8 @@ You should create a `path_to_target` variable set to an empty list within your `
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
def binary_search(search_list, value):
|
||||
--fcc-editable-region--
|
||||
pass
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
@ -60,9 +60,9 @@ Your `high` variable should be set to `len(search_list) - 1`.
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
def binary_search(search_list, value):
|
||||
path_to_target = []
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
@ -37,6 +37,7 @@ def binary_search(search_list, value):
|
||||
path_to_target = []
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
@ -35,9 +35,9 @@ def binary_search(search_list, value):
|
||||
path_to_target = []
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
while low <= high:
|
||||
--fcc-editable-region--
|
||||
pass
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
@ -34,10 +34,9 @@ def binary_search(search_list, value):
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
--fcc-editable-region--
|
||||
while low <= high:
|
||||
mid = (low + high) // 2
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
@ -32,10 +32,10 @@ def binary_search(search_list, value):
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
--fcc-editable-region--
|
||||
while low <= high:
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
@ -49,6 +49,7 @@ def binary_search(search_list, value):
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
@ -47,15 +47,15 @@ def binary_search(search_list, value):
|
||||
path_to_target = []
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
|
||||
while low <= high:
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
if value == value_at_middle:
|
||||
return path_to_target
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
@ -47,12 +47,13 @@ def binary_search(search_list, value):
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
|
||||
if value == value_at_middle:
|
||||
return path_to_target
|
||||
break
|
||||
|
||||
return []
|
||||
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
@ -38,13 +38,14 @@ def binary_search(search_list, value):
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
if value == value_at_middle:
|
||||
return path_to_target
|
||||
|
||||
--fcc-editable-region--
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
break
|
||||
|
||||
return []
|
||||
|
||||
print(binary_search([1, 2, 3, 4, 5], 3))
|
||||
|
||||
@ -36,14 +36,15 @@ def binary_search(search_list, value):
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
|
||||
if value == value_at_middle:
|
||||
return path_to_target
|
||||
--fcc-editable-region--
|
||||
elif value > value_at_middle:
|
||||
pass
|
||||
--fcc-editable-region--
|
||||
pass
|
||||
--fcc-editable-region--
|
||||
break
|
||||
|
||||
return []
|
||||
|
||||
print(binary_search([1, 2, 3, 4, 5], 3))
|
||||
|
||||
@ -30,12 +30,12 @@ def binary_search(search_list, value):
|
||||
path_to_target = []
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
|
||||
while low <= high:
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
|
||||
if value == value_at_middle:
|
||||
return path_to_target
|
||||
elif value > value_at_middle:
|
||||
@ -43,8 +43,9 @@ def binary_search(search_list, value):
|
||||
--fcc-editable-region--
|
||||
break
|
||||
--fcc-editable-region--
|
||||
return []
|
||||
|
||||
return []
|
||||
|
||||
print(binary_search([1, 2, 3, 4, 5], 3))
|
||||
print(binary_search([1, 2, 3, 4, 5, 9], 4))
|
||||
```
|
||||
|
||||
@ -35,21 +35,21 @@ def binary_search(search_list, value):
|
||||
path_to_target = []
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
|
||||
while low <= high:
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
|
||||
if value == value_at_middle:
|
||||
return path_to_target
|
||||
elif value > value_at_middle:
|
||||
low = mid + 1
|
||||
else:
|
||||
high = mid - 1
|
||||
|
||||
return []
|
||||
|
||||
return []
|
||||
|
||||
print(binary_search([1, 2, 3, 4, 5], 3))
|
||||
print(binary_search([1, 2, 3, 4, 5, 9], 4))
|
||||
--fcc-editable-region--
|
||||
|
||||
@ -33,19 +33,19 @@ def binary_search(search_list, value):
|
||||
path_to_target = []
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
|
||||
while low <= high:
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
|
||||
if value == value_at_middle:
|
||||
return path_to_target
|
||||
elif value > value_at_middle:
|
||||
low = mid + 1
|
||||
else:
|
||||
high = mid - 1
|
||||
|
||||
|
||||
--fcc-editable-region--
|
||||
return []
|
||||
--fcc-editable-region--
|
||||
|
||||
@ -37,11 +37,12 @@ def binary_search(search_list, value):
|
||||
path_to_target = []
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
while low <= high:
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
|
||||
if value == value_at_middle:
|
||||
--fcc-editable-region--
|
||||
return path_to_target
|
||||
@ -50,7 +51,7 @@ def binary_search(search_list, value):
|
||||
low = mid + 1
|
||||
else:
|
||||
high = mid - 1
|
||||
|
||||
|
||||
return [], "Value not found"
|
||||
|
||||
print(binary_search([1, 2, 3, 4, 5], 3))
|
||||
@ -65,19 +66,19 @@ def binary_search(search_list, value):
|
||||
path_to_target = []
|
||||
low = 0
|
||||
high = len(search_list) - 1
|
||||
|
||||
|
||||
while low <= high:
|
||||
mid = (low + high) // 2
|
||||
value_at_middle = search_list[mid]
|
||||
path_to_target.append(value_at_middle)
|
||||
|
||||
|
||||
if value == value_at_middle:
|
||||
return path_to_target, f"Value found at index {mid}"
|
||||
elif value > value_at_middle:
|
||||
low = mid + 1
|
||||
else:
|
||||
high = mid - 1
|
||||
|
||||
|
||||
return [], "Value not found"
|
||||
|
||||
print(binary_search([1, 2, 3, 4, 5], 3))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user