Maximum Sub Array
unknown
c_cpp
16 days ago
355 B
3
Indexable
Never
class Solution { public: int maxSubArray(vector<int>& nums) { int maxSum=INT_MIN, sum=0; int size=nums.size(); for(int i=0;i<size;i++) { sum+=nums[i]; if(sum>maxSum) maxSum=sum; if(sum<0) sum=0; } return maxSum; } };
Leave a Comment