Posted onEdited onInLeetCodeDisqus: Symbols count in article: 202Reading time ≈1 mins.
dp O(n) time O(1) space
1 2 3 4 5 6 7 8 9 10 11
classSolution { public: intmaxSubArray(vector<int>& nums){ int f = 0, res = INT_MIN; for (int x : nums) { f = max(f, 0) + x; res = max(res, f); } return res; } };