C++ 7lines 8ms DP


  • 3
    B

    no need to explain

    class Solution {
    public:
        int maxSubArray(vector<int>& nums) 
        {
            if(nums.empty()) return 0;
            int ans = INT_MIN;
            int lastBest = 0;
            for(int i = 0; i < nums.size(); i++ )
            {
                lastBest = max(lastBest+nums[i], nums[i]);
                ans = max(ans, lastBest);
            }
            return ans;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.