classSolution:defmaxSubArray(self,nums: List[int]) ->int: n =len(nums)if n ==0:return0 a, total =-1e12,-1e12for num in nums: a =max(num + a, num) total =max(a, total)return total
classSolution:defmaxSubArray(self,nums: List[int]) ->int: n =len(nums)if n ==0:return0 l, r, m, s = self.sub_array(nums, 0, n -1)return mdefsub_array(self,array,start,end):if start == end: t = array[start]return t, t, t, t # left, right, max, sum mid = (start + end) //2 ll, lr, lm, ls = self.sub_array(array, start, mid) rl, rr, rm, rs = self.sub_array(array, mid +1, end) l =max(ll, ls + rl) r =max(rr, rs + lr) m =max([lm, rm, lr + rl]) s = ls + rsreturn l, r, m, s