Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created December 1, 2019 12:55
Show Gist options
  • Save inspirit941/2ce9ccc8fe0421686faded0feb522fe6 to your computer and use it in GitHub Desktop.
Save inspirit941/2ce9ccc8fe0421686faded0feb522fe6 to your computer and use it in GitHub Desktop.
def solution(triangle):
# 첫째 줄은 index가 0이므로, 둘째 줄부터 계산한다.
for rows in range(1, len(triangle)):
# 각 줄의 index 값별로 비교한다.
for idx in range(rows + 1):
# 가장 왼쪽 값인 경우
if idx == 0:
triangle[rows][idx] += triangle[rows-1][idx]
# 가장 오른쪽 값인 경우
elif idx == rows:
triangle[rows][idx] += triangle[rows-1][-1]
else:
triangle[rows][idx] += max(triangle[rows-1][idx-1], triangle[rows-1][idx])
# 가장 마지막 줄의 최댓값을 구하면 된다.
return max(triangle[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment