Skip to content

Instantly share code, notes, and snippets.

@limboinf
Created January 4, 2017 03:27
Show Gist options
  • Save limboinf/dced11596d8ec6e8ace218f9b419a550 to your computer and use it in GitHub Desktop.
Save limboinf/dced11596d8ec6e8ace218f9b419a550 to your computer and use it in GitHub Desktop.
回文
# coding=utf-8
n = int(raw_input().strip())
item = [int(x) for x in raw_input().strip().split()]
def huiwen(item, head, tail):
times=0
left = item[head]
right = item[tail]
while (head < tail):
if left < right:
head += 1
left += item[head]
times += 1
continue
elif left > right:
tail -= 1
right += item[tail]
times += 1
continue
elif left == right:
head += 1
tail -= 1
left = item[head]
right = item[tail]
return times
print huiwen(item, 0, n-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment