Simple Python solution (beats 89%)


  • 0
    F
    class Solution(object):
        def maxSubArray(self, a):
            cur_sum, mx_sum = 0, float('-inf')
    
            for n in a:
                cur_sum+=n
                
                if cur_sum > mx_sum:
                    mx_sum = cur_sum
                    
                if cur_sum <= 0:
                    cur_sum = 0
                
            return mx_sum
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.