#include <climits>
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int curr = 0;
int res = INT_MIN;
for(int i=0; i<nums.size();i++){
if(curr<0){
curr = 0;
}
curr += nums[i];
res = res> curr? res: curr;
}
return res;
}
};
class Solution {
public:
int maxSubArray(vector<int>& nums) {
vector<int>::iterator it = nums.begin();
int maxSum = *it;
int theSum = *it;
for(it = it+1 ; it != nums.end(); it++){
theSum = (theSum + *it )> (*it) ? (theSum + *it ) : (*it);
maxSum = maxSum > theSum ? maxSum: theSum;
}
return maxSum;
}
};