ac8444bb41
- find_max_linear: 线性扫描 O(n)(原 find_max 重命名+alias兼容) - find_max_bubble: 冒泡排序 O(n²) - find_max_quickselect: 快速选择 partition O(n) avg - 37 个测试(7×3 参数化 + 9 一致性 + 7 原有)
19 lines
419 B
Python
19 lines
419 B
Python
"""find_max_linear — 线性扫描法找最大值"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
def find_max_linear(nums: list[int | float]) -> int | float | None:
|
|
"""返回列表中的最大值,空列表返回 None。"""
|
|
if not nums:
|
|
return None
|
|
result = nums[0]
|
|
for num in nums[1:]:
|
|
if num > result:
|
|
result = num
|
|
return result
|
|
|
|
|
|
# 兼容别名
|
|
find_max = find_max_linear
|