knakul853

Untitled

Jun 10th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. /*
  2.  
  3. knakul853
  4.  
  5. */
  6. class Solution {
  7. public:
  8.     int maxSubArray(vector<int>& nums) {
  9.         int n = nums.size();
  10.         if(n==0)return 0;
  11.      
  12.         int best =  INT_MIN;
  13.         int cur = 0;
  14.        
  15.         for(const int& num :  nums )
  16.         {
  17.             cur = max( cur, 0 );
  18.             cur = max(num, cur +num );
  19.             best = max(best, cur);
  20.         }
  21.        
  22.         return best;
  23.     }
  24. };
Add Comment
Please, Sign In to add comment