Data Structure & Algorithm: Level-1 Problem #8. Max Slice

Given a list of integers including positive and negative ones, find out the maximum sum from any slice of this list.

Sample Input:

[3,-2,2,-3,4,-1,2,1,-5,4,-2,2]

Sample Output:

6

From the above sample input, sublist [4,-1,2,1] has the maximum sum of 6.


数据结构和算法:初级练习题 #8 – 数组切片求最大总和


给定一组数字,包括正数和负数,找出该数组当中可以得到最大总和的子数组。

样例输入:

[3,-2,2,-3,4,-1,2,1,-5,4,-2,2]

样例输出:

6

在上面的输入样例中,子数组 [4, -1, 2, 1] 可以得到最大总和 6。


Python Solution

Max Slice of a List