Created
May 6, 2018 17:19
-
-
Save 5minho/5c2405c9d37ad0137fca6b8c1b28d91c to your computer and use it in GitHub Desktop.
Codility TapeEquilibrium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(A): | |
left_sum, right_sum = A[0], sum(A[1:]) | |
result = abs(left_sum - right_sum) | |
for x in range(1, len(A) - 1): | |
left_sum, right_sum = left_sum + A[x], right_sum - A[x] | |
result = min(result, abs(left_sum - right_sum)) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment