53. 最大子序和

這道題考了一萬遍了,再不能一次對太沒天理了。不過說的分治哪個沒看懂

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;
}
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章