SHARE
TWEET

Kadane's algorithm

keverman Feb 12th, 2018 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int maxSubarraySum(std::vector<int> T)
  2. {
  3.     int mx = -0x3f3f3f3f, e = 0;
  4.  
  5.     for (unsigned int i = 0; i < T.size(); i++)
  6.     {
  7.         e += T[i];
  8.         mx = std::max(mx, e);
  9.         e = std::max(e, 0);
  10.     }
  11.  
  12.     return mx;
  13. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top