https://leetcode.com/problems/maximum-subarray/description/
int maxSubArray(vector<int>& nums) {
int mx = nums[0], s = 0;
for(int n: nums) {
s += n;
mx = max(s,mx);
if(s<0) s = 0;
}
return mx;
}
No comments:
Post a Comment