Created
July 21, 2021 05:10
-
-
Save igorvanloo/b55efdfb192bdb29555cf1909cf85e70 to your computer and use it in GitHub Desktop.
Problem 18
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
def top_to_bottom(tri): | |
for i in range(1,len(tri)): | |
a = len(triangle[i]) | |
for j in range(0, a): | |
if j == 0: | |
tri[i][j] += tri[i-1][j] | |
elif j == a-1: | |
tri[i][j] += tri[i-1][j-1] | |
else: | |
tri[i][j] += max(tri[i-1][j],tri[i-1][j-1]) | |
return max(tri[-1]) | |
def bottom_to_top(tri): | |
for i in reversed(range(len(triangle) - 1)): | |
for j in range(len(triangle[i])): | |
if triangle[i + 1][j] >= triangle[i + 1][j + 1]: | |
triangle[i][j] += triangle[i + 1][j] | |
else: | |
triangle[i][j] += triangle[i + 1][j + 1] | |
return triangle[0][0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment