Created
January 4, 2017 03:27
-
-
Save limboinf/dced11596d8ec6e8ace218f9b419a550 to your computer and use it in GitHub Desktop.
回文
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
# 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