-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
53.py
23 lines (23 loc) · 857 Bytes
/
53.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
__________________________________________________________________________________________________
sample 28 ms submission
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
m=msf=nums[0]
for num in nums[1:]:
msf=num+max(0,msf)
m=max(m,msf)
return m
__________________________________________________________________________________________________
sample 13104 kb submission
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
max_sum = float('-inf')
cur_sum = 0
for num in nums:
cur_sum += num
if cur_sum > max_sum:
max_sum = cur_sum
if cur_sum < 0:
cur_sum = 0
return max_sum
__________________________________________________________________________________________________