Easy C++ (Not Medium :-) )


  • 0
    G
        int maxSubArray(vector<int>& nums) {
            int sum = 0, max_sum = INT32_MIN;
            for (auto n : nums) {
                sum = max(sum + n, n);      // extend an existing subarray with 'n' OR start a new subarray with 'n'
                max_sum = max(max_sum, sum);
            }
            return max_sum;
        }
    

Log in to reply
 

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