Skip to content

Commit a000916

Browse files
authored
Merge pull request fnplus#652 from namanbansal013/namanbansal013
Created Kadane.cpp
2 parents 62a1bd6 + f6df482 commit a000916

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Algorithms/Kadane.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
long long kadane(long long array[], int n) {
2+
long long max_so_far = INT_MIN, max_ending_here = 0;
3+
for (int i = 0; i < n; i++)
4+
{
5+
max_ending_here = max_ending_here + array[i];
6+
if (max_so_far < max_ending_here)
7+
max_so_far = max_ending_here;
8+
9+
if (max_ending_here < 0)
10+
max_ending_here = 0;
11+
}
12+
return max_so_far;
13+
}

0 commit comments

Comments
 (0)