We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 664a309 commit 57e1841Copy full SHA for 57e1841
maximum_subarray/solution2.py
@@ -0,0 +1,15 @@
1
+class Solution:
2
+ # @param A, a list of integers
3
+ # @return an integer
4
+ def maxSubArray(self, A):
5
+ if not A:
6
+ return 0
7
+ res = A[0]
8
+ cur_sum = A[0]
9
+ n = len(A)
10
+ for i in range(1, n):
11
+ cur_sum = max(cur_sum + A[i], A[i])
12
+ res = max(res, cur_sum)
13
+ # If negative sum is not allowed, add the following line:
14
+ # if res < 0: return 0
15
+ return res
0 commit comments