Skip to content

Instantly share code, notes, and snippets.

@ShinJJang
Created January 10, 2020 13:30
Show Gist options
  • Save ShinJJang/46455b1a29373aae51861e304daecb1e to your computer and use it in GitHub Desktop.
Save ShinJJang/46455b1a29373aae51861e304daecb1e to your computer and use it in GitHub Desktop.
def solution(A):
sum_a = sum(A)
left = A[0]
right = sum_a - left
min_diff = abs(right - left)
for idx in range(1, len(A)-1):
cur = A[idx]
left += cur
right -= cur
diff = abs(right - left)
# print(idx, cur, left, right, diff, min_diff)
if min_diff > diff:
min_diff = diff
return min_diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment