File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -214,7 +214,9 @@ def binary_search(sorted_collection: list[int], item: int) -> int:
214214 midpoint = left + (right - left ) // 2
215215 current_item = sorted_collection [midpoint ]
216216 if current_item == item :
217- result = midpoint # Found the item, but continue to find leftmost occurrence
217+ result = (
218+ midpoint # Found the item, but continue to find leftmost occurrence
219+ )
218220 right = midpoint - 1 # Look for more occurrences on the left
219221 elif item < current_item :
220222 right = midpoint - 1
@@ -284,7 +286,7 @@ def binary_search_by_recursion(
284286 right = len (sorted_collection ) - 1
285287 if list (sorted_collection ) != sorted (sorted_collection ):
286288 raise ValueError ("sorted_collection must be sorted in ascending order" )
287-
289+
288290 # Helper function for the binary search
289291 def _binary_search_recursive (left_idx : int , right_idx : int ) -> int :
290292 if right_idx < left_idx :
@@ -302,7 +304,7 @@ def _binary_search_recursive(left_idx: int, right_idx: int) -> int:
302304 return _binary_search_recursive (left_idx , midpoint - 1 )
303305 else :
304306 return _binary_search_recursive (midpoint + 1 , right_idx )
305-
307+
306308 return _binary_search_recursive (left , right )
307309
308310
You can’t perform that action at this time.
0 commit comments