Skip to content

Commit 9c41ec3

Browse files
committed
Time: 235 ms (5.04%), Space: 67.8 MB (5.95%) - LeetHub
1 parent dab5217 commit 9c41ec3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

maximum-subarray/maximum-subarray.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int maxSubArray(vector<int>& nums) {
4+
5+
int maxSum = INT_MIN, currentSum = 0;;
6+
for(int i=0;i<nums.size();i++) {
7+
currentSum = currentSum + nums[i];
8+
if(maxSum<currentSum) {
9+
maxSum = currentSum;
10+
} if(currentSum<0) {
11+
currentSum = 0;
12+
}
13+
}
14+
15+
return maxSum;
16+
}
17+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy