mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-17 16:51:46 +00:00
16 lines
354 B
C++
16 lines
354 B
C++
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;
|
|
}
|
|
};
|