mirror of
https://github.com/huihut/interview.git
synced 2026-03-13 10:02:55 +08:00
First Update
This commit is contained in:
13
Problems/LeetcodeProblems/maximum-subarray.h
Normal file
13
Problems/LeetcodeProblems/maximum-subarray.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user