《数据结构》最大子列和模板题, 时间复杂度 O(n)

class Solution {
public:
    int maxsumofSubarray(vector<int>& arr) {
        int maxn = 0, thismaxn = 0;

        for ( int i = 0; i < arr.size(); i++ ) {
            thismaxn += arr[i];

            if ( thismaxn > maxn) maxn = thismaxn;
            if ( thismaxn < 0 ) thismaxn = 0;
        }
        return maxn;
    }
};