简介

刷题

参考链接

https://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484?tpId=117

核心思想

遍历一遍得到结果

code

class Solution {
public:
    int FindGreatestSumOfSubArray(vector<int> array) {
        if(array.size() == 0) {
            return 0;
        }
        int curSum = 0;
        int greatestSum = 0x80000000;
        for(int i=0; i<array.size(); i++) {
            if(curSum <= 0) {
                curSum=array[i];
            } else{
                curSum+=array[i];
            }
            if(curSum > greatestSum) {
                greatestSum = curSum;
            }
        }
        return greatestSum;
    }
};
posted on 2021-08-10 16:55  HDU李少帅  阅读(30)  评论(0编辑  收藏  举报