Created
March 26, 2016 02:55
-
-
Save ta1hia/d8219c607e2b9feb290f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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 | |
L = len(A) | |
n = 0 | |
if L == 1: | |
return 0 | |
for i in range(L-2, -1, -1): | |
if A[i]: # 1 or west | |
A[i] = A[i+1] + 1 | |
else: # 0 or east | |
A[i] = A[i+1] | |
n = n + A[i] | |
if n > 1000000000: | |
return -1 | |
return n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment