mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-18 00:57:17 +00:00
Initial commit
This commit is contained in:
15
Easy/maximum-subarray/solution.cpp
Normal file
15
Easy/maximum-subarray/solution.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
class Solution {
|
||||
public:
|
||||
int maxSubArray(std::vector<int> &nums) {
|
||||
int max = INT32_MIN;
|
||||
int tmax = 0;
|
||||
for (int i = 0; i < nums.size(); ++i) {
|
||||
tmax = tmax + nums[i];
|
||||
if (max < tmax)
|
||||
max = tmax;
|
||||
if (tmax < 0)
|
||||
tmax = 0;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user