int maxSubArray(vector<int>& nums) {
int maxSum = nums.front();
for(int i = 1; i<nums.size(); i++) {
nums[i] = max(nums[i], nums[i1] + nums[i]);
maxSum = max(maxSum, nums[i]);
}
return maxSum;
}
Simple C++ solution with 8ms

You don't need to overwrite the vector. Once you use the value nums[i] you've taken it into account and don't need to store it. My solution is similar but you don't need to store the intermediate values.
class Solution { public: int maxSubArray(vector<int>& nums) { int curr_mx = 0, mx = std::numeric_limits<int>::min(); for (int n : nums) { curr_mx = max(curr_mx + n, n); mx = max(mx, curr_mx); } return mx; } };