题解 | #子数组的最大累加和问题#
子数组的最大累加和问题
http://www.nowcoder.com/practice/554aa508dd5d4fefbf0f86e5fe953abd
class Solution { public: /** * max sum of the subarray * @param arr int整型vector the array * @return int整型 */ int maxsumofSubarray(vector<int>& a) { // write code here int n = a.size(); int maxnum = a[0]; for(int i = 1; i < n; i++){ a[i] = max(a[i], a[i] + a[i - 1]); maxnum = max(maxnum, a[i]); } return maxnum; } };