Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int maxSubArray(vector<int>& nums) {
- int maxSum = INT_MIN;
- int currentSum = 0;
- for (int i = 0; i < nums.size(); i++) {
- currentSum += nums[i];
- if (currentSum > maxSum) {
- maxSum = currentSum;
- }
- if (currentSum < 0) {
- currentSum = 0;
- }
- }
- return maxSum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement