Skip to content

Commit

Permalink
programmers triangle 문제
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyeongchoi committed Sep 13, 2020
1 parent 763adb3 commit e8fc6bc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions argorithm/triangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def solution(triangle):
answer = 0
for i in range(1, len(triangle)):
for j in range(i+1):
if j == 0:
triangle[i][j] += triangle[i-1][j]
elif j == i:
triangle[i][j] += triangle[i-1][-1]
else:
triangle[i][j] += max(triangle[i-1][j-1],triangle[i-1][j])
return max(triangle[-1])


if __name__ == '__main__':
real_answer = solution([[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]])
print(real_answer)

0 comments on commit e8fc6bc

Please sign in to comment.