imashutosh51

Maximum Subarray

Feb 4th, 2026
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.24 KB | None | 0 0
  1. class Solution:
  2.     def maxSubArray(self, nums: List[int]) -> int:
  3.         cur=0
  4.         ans=-inf
  5.         for i in nums:
  6.             cur+=i
  7.             ans=max(ans,cur)
  8.             if cur<0:
  9.                 cur=0
  10.         return ans
  11.        
Advertisement
Add Comment
Please, Sign In to add comment