题解 | #连续最大和#
连续最大和
https://www.nowcoder.com/practice/5a304c109a544aef9b583dce23f5f5db
def max_subarray_sum(arr): if not arr: return 0 cur_sum = max_sum = arr[0] for num in arr[1:]: cur_sum = max(num, cur_sum + num) max_sum = max(max_sum, cur_sum) return max_sum # 输入部分(假设通过input()函数获取) n = int(input()) nums = list(map(int, input().split())) result = max_subarray_sum(nums) print(result)