贪心算法-leetcode53 最大子序和
程序员文章站
2022-07-03 11:05:51
...
题目:
解析:贪心算法
解答:
int maxSubArray(int* nums, int numsSize){
int subsum = 0, maxsum = -2147483648;
for(int i=0;i<numsSize;i++)
{
subsum+=nums[i];
if(subsum>maxsum)
maxsum=subsum;
if(subsum<0)
subsum=0;
}
return maxsum;
}
上一篇: flash怎么快速画一排松树?