Skip to content

Commit

Permalink
Create c++ code for maximum subarray sum
Browse files Browse the repository at this point in the history
  • Loading branch information
shirali-saraf committed Oct 6, 2023
1 parent 067b21a commit 95328c1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions c++ code for maximum subarray sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
int maxSubArray(vector<int>& nums) {
int l=nums.size();
int max=INT_MIN;
int sum=0;

for(int i=0;i<l;i++){

sum=sum+nums[i];
if(sum>max){
max=sum;
}
if(sum<0){
sum=0;
}

}
return max;
}

0 comments on commit 95328c1

Please sign in to comment.