53. Maximum Subarray
I solved this problem using C++.
My idea: use dynamic programming.
1 | class Solution { |
use currentSum to store the max subarray sum with the current index.
use maxSum to store the max subarray sum of all indices.currentSum is updated by max(nums[i], currentSum + nums[i]).maxSum is updated by max(maxSum, currentSum).