Oh right this thing
This commit is contained in:
parent
ad65630b3f
commit
a498ff949c
@ -625,3 +625,16 @@ def traverse_neighborly_node(
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
yield from traverse_neighborly_node(neighbor, memo)
|
yield from traverse_neighborly_node(neighbor, memo)
|
||||||
|
|
||||||
|
|
||||||
|
def find_min_in_rotated_array(nums: list[int]) -> int:
|
||||||
|
if nums[0] <= nums[-1]:
|
||||||
|
return nums[0]
|
||||||
|
|
||||||
|
if len(nums) <= 3:
|
||||||
|
return min(nums)
|
||||||
|
|
||||||
|
if nums[len(nums) // 2] > nums[-1]:
|
||||||
|
return find_min_in_rotated_array(nums[len(nums) // 2 :])
|
||||||
|
|
||||||
|
return find_min_in_rotated_array(nums[: (len(nums) // 2) + 1])
|
||||||
|
@ -491,3 +491,15 @@ def test_copy_neighborly_node(inlist):
|
|||||||
assert id(orig) != id(copied)
|
assert id(orig) != id(copied)
|
||||||
assert orig == copied
|
assert orig == copied
|
||||||
assert stuff.neighborly_node_to_list(orig) == stuff.neighborly_node_to_list(copied)
|
assert stuff.neighborly_node_to_list(orig) == stuff.neighborly_node_to_list(copied)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("nums", "expected"),
|
||||||
|
[
|
||||||
|
([3, 4, 5, 1, 2], 1),
|
||||||
|
([4, 5, 6, 7, 0, 1, 2], 0),
|
||||||
|
([11, 13, 15, 17], 11),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_find_min_in_rotated_array(nums: list[int], expected: int):
|
||||||
|
assert stuff.find_min_in_rotated_array(nums) == expected
|
||||||
|
Loading…
Reference in New Issue
Block a user