Commit d62e979c authored by yaozc's avatar yaozc
Browse files

problem 53 solved

parent 37d57186
......@@ -213,3 +213,19 @@ public:
return result;
}
};
//53. Maximum Subarray
//用了遍历的方法,此题可作为DP练习
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int maxsofar = nums[0];
int maxendinghere = nums[0];
for(int i=1; i<nums.size(); i++){
maxendinghere = max(nums[i]+maxendinghere, nums[i]);
maxsofar = max(maxsofar, maxendinghere);
}
return maxsofar;
}
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment