题解 | #连续子数组的最大和#
连续子数组的最大和
https://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484
class Solution { public: int FindGreatestSumOfSubArray(vector<int> array) { int max_val = INT_MIN; int cur = 0; for (int i = 0; i < array.size(); ++i) { cur += array[i]; max_val = max(max_val, cur); cur = cur < 0 ? 0 : cur; } return max_val; } };
2023-剑指-DP 文章被收录于专栏
2023-剑指-DP