写一个算法
就是定义一个局部最小和全局最小啦
def min_subarray_sum(arr):
if not arr:
return 0
current_min_sum = arr[0]
global_min_sum = arr[0]
for i in range(1, len(arr)):
current_min_sum = min(arr[i], current_min_sum + arr[i])
global_min_sum = min(global_min_sum, current_min_sum)
print('current_min_sum',current_min_sum)
print('global_min_sum',global_min_sum)
return global_min_sum
arr = [3, -4, 2, -3, -1, 7, -5]
result = min_subarray_sum(arr)
print(f"连续子数组的最小和是: {result}")