Easy C++ Solution


  • 0
    Y
    class Solution {
    public:
        int maxSubArray(vector<int>& nums) {
            int sum = 0,ans = INT_MIN;
            for (auto num : nums) {
                    sum += num;
                    ans = max(ans,sum);
                    if (sum < 0)
                        sum = 0;
            }
           return ans;
        }
    };
    

Log in to reply
 

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