class Solution {public: int maxSubArray(vector & nums) { int res = nums[0], cur = nums[0]; for (int i = 1; i < nums.size(); i++) { cur = max(cur, 0) + nums[i]; res = max(res, cur); } return res; }};
本文共 324 字,大约阅读时间需要 1 分钟。
class Solution {public: int maxSubArray(vector & nums) { int res = nums[0], cur = nums[0]; for (int i = 1; i < nums.size(); i++) { cur = max(cur, 0) + nums[i]; res = max(res, cur); } return res; }};
转载于:https://www.cnblogs.com/JTechRoad/p/10059552.html