Minimum subarray difference in python
问题 Consider I have a non-empty array of integers: A0..An . And consider a parameter P where 0 < P <=n . I need to find a minimum absolute difference between left and right subarray splited by P. For example: A[0] = 3 A[1] = 1 A[2] = 2 A[3] = 4 A[4] = 3 P = 1, difference = |3 − 10| = 7 P = 2, difference = |4 − 9| = 5 P = 3, difference = |6 − 7| = 1 P = 4, difference = |10 − 3| = 7 The solution in this case is 1 I finished with the code below: def solution(A): lsum, rsum = A[0], sum(A[1:]) diff =