C++ different idea


  • 0
    class Solution {
    public:
        int maxSubArray(vector<int>& nums) {
            int sum = 0;
            int min_sum = 0;
            int ans = INT_MIN;
            for(int n: nums){
                sum += n;
                ans = max(ans, sum - min_sum);
                min_sum = min(min_sum, sum);
            }
            return ans;
        }
    };
    

Log in to reply
 

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