Advertisement
keverman

Kadane's algorithm

Feb 12th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. int Kadane(std::vector<int>& T)
  2. {
  3.     for (int i = 0, mx = 0, sum = 0; i < T.size(); i++)
  4.     {
  5.         sum += T[i];
  6.         mx = max(mx, sum = max(sum, 0));
  7.     }
  8.     return mx;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement