Leetcode53:最大子序和
作者:互联网
/**
* @param {number[]} nums
* @return {number}
*/
var maxSubArray = function(nums) {
let ans = nums[0];
let sum = 0;
for(const num of nums) {
if(sum > 0) {
sum += num;
} else {
sum = num;
}
ans = Math.max(ans, sum);
}
return ans;
};
标签:return,最大,nums,sum,Leetcode53,number,num,ans,子序 来源: https://blog.csdn.net/qq_52207728/article/details/117339509