Untitled

 avatar
user_9124840
plain_text
8 days ago
355 B
3
Indexable
Never
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        cin.tie(nullptr)->sync_with_stdio(0);
        int sz = nums.size();
        int sum = nums[0], ans = nums[0];
        for (int i = 1; i < sz; ++i) {
            sum = max(nums[i] + sum, nums[i]);

            ans = max(ans, sum);
        }
        return ans;
    }
};
Leave a Comment