mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
13 lines
320 B
C++
13 lines
320 B
C++
#define MIN_INT -2147483648
|
|
class Solution {
|
|
public:
|
|
int maxSubArray(vector<int>& nums) {
|
|
int max = MIN_INT, temp = 0;
|
|
for(auto i = 0; i < nums.size(); ++i) {
|
|
temp += nums[i];
|
|
if(temp > max) max = temp;
|
|
if(temp < 0) temp = 0;
|
|
}
|
|
return max;
|
|
}
|
|
}; |