Advertisement
5m1le

leetcode3

Apr 3rd, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxSubArray(vector<int>& nums) {
  4.         int ans = nums[0];
  5.         int sum = 0;
  6.         for(auto i : nums) {
  7.             sum += i;
  8.             ans = max(ans, sum);
  9.             sum = max(sum, 0);
  10.         }
  11.         return ans;
  12.     }
  13.  
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement