# Codility在线学习第一题学习过程

score: 100

def solution(A):
# write your code in Python 2.7
one = A[0]
two = sum(A[1:])
data = abs(one - two)
for row in range(2, len(A)-1):
one = one + A[row-1]
two = two - A[row-1]
bad = abs(one - two)
if bad < data:
data = bad
return data

score: 50

def solution(A):
# write your code in Python 2.7
data = abs(A[0] - sum(A[1:]))
for row in range(2, len(A)-1):
one = sum(A[0:row])
two = sum(A[row:])
bad = abs(one - two)
if bad < data:
data = bad
return data

score: 41

def solution(A):
# write your code in Python 2.7
data = 0
for row in range(1, len(A)-1):
one = sum(A[0:row])
two = sum(A[row:])
bad = abs(one - two)
if data == 0:
data = bad
if bad < data:
data = bad
return data

score: 25

# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"

def solution(A):
# write your code in Python 2.7
data = 0
for row in range(1, len(A)-1):
one = sum(map(abs, A[0:row]))
two = sum(map(abs, A[row:]))
bad = abs(one - two)
if data == 0:
data = bad
if bad < data:
data = bad
return data

def solution(A):
# write your code in Python 2.7
data = 0
A = map(abs, A)
for row in range(1, len(A)-1):
one = sum(A[0:row])
two = sum(A[row:])
bad = abs(one - two)
if data == 0:
data = bad
if bad < data:
data = bad
return data

def solution(A):
# write your code in Python 2.7
sum_left = A[0]
sum_right = sum(A[1:])
diff_min = abs(sum_left - sum_right)
length = len(A)
i = 1
for i in range(1, length - 1):
sum_left += A[i]
sum_right -= A[i]
diff = abs(sum_left - sum_right)
if(diff_min > diff):
diff_min = diff

return diff_min

score: 16

# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"

def solution(A):
# write your code in Python 2.7
data = 0
for row in A:
one = sum(map(abs, A[0:A.index(row)]))
two = sum(map(abs, A[A.index(row):]))
bad = abs(one - two)
if (A.index(row)) == 0 or (A.index(row) == (len(A)-1)):
continue
if A.index(row) == 1:
data = bad
if bad < data:
data = bad
return data

A [0] = 3
A [1] = 1
A [2] = 2
A [3] = 4
A [4] = 3

P = 1，差值= | 3 - 10 | = 7
P = 2，差= | 4 - 9 | = 5
P = 3，差值= | 6 - 7 | = 1
P = 4，差= | 10 - 3 | = 7

，考虑N个整数的非空零索引数组A，返回可以达到的最小差异。

A [0] = 3
A [1] = 1
A [2] = 2
A [3] = 4
A [4] = 3

N是内范围内的整数[2 .. 100000];

0 0