连续子数组的最大和

class Solution {
public:
int FindGreatestSumOfSubArray(vector<int> array) {
int n = array.size();
if(0 == n)
return 0;</int>

    int temp =array[0];
    int max = temp;
    for(int i = 1; i<n; i++)
    {
        if(temp > 0)
            temp = temp + array[i];
        else
            temp = array[i];

        max = max > temp ? max:temp;
    }
    return max;
}

};

全部评论

相关推荐

sagima:然后这个帖子又登上了
点赞 评论 收藏
分享
02-11 12:20
门头沟学院 Java
面试中的青提很胆小:我不信有比我们学校更逆天的,计算机专业就业第一位是我们学校二餐厅的打印店
点赞 评论 收藏
分享
01-07 07:54
已编辑
门头沟学院 前端工程师
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务