This is my CPP solution.
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int n = nums.size();
int dp[n];
int sum = nums[0];
dp[0] = nums[0];
for(int i=1;i<n;i++){
dp[i] = max(nums[i],nums[i]+dp[i-1]);
sum = max(sum,dp[i]);
}
return sum;
}
};