這道題考了一萬遍了,再不能一次對太沒天理了。不過說的分治哪個沒看懂
class Solution {
public:
int maxSubArray(vector<int>& nums)
{
int temp = nums[0];
int n = nums.size();
int maxx = temp;
for(int i=1;i<n;++i)
{
temp = temp>0 ? temp+nums[i] : nums[i];
maxx = max(maxx, temp);
}
return maxx;
}
};