728x90
다른사람의 풀이
def solution(land):
for i in range(0, len(land)-1):
land[i+1][0] += max(land[i][1],land[i][2],land[i][3])
land[i+1][1] += max(land[i][0],land[i][2],land[i][3])
land[i+1][2] += max(land[i][0],land[i][1],land[i][3])
land[i+1][3] += max(land[i][0],land[i][1],land[i][2])
return max(land[len(land)-1])
def solution(land):
for i in range(1, len(land)):
for j in range(len(land[0])):
land[i][j] = max(land[i -1][: j] + land[i - 1][j + 1:]) + land[i][j]
return max(land[-1])
print(max([1]+[5]))
# output = 5
python max 내부의 인자를 iterable 끼리 합연산인데 그 중 큰 값을 return한다.
왜 그러는지 이해는 안가지만.
위의 솔루션이 더 직관적으로 이해는되고,
해당 열을 제외한 값 중에서 최대값을 해당 열을 포함시킨 값으로 업데이트 시킴.
결국 아래의 솔루션도 같은 맥락인데 for 문을 한번더 사용하지만 코드는 더 간결해짐.
728x90
'Algorithm' 카테고리의 다른 글
| [프로그래머스] 피보나치 수 파이썬 (0) | 2021.03.16 |
|---|---|
| [프로그래머스] 숫자의 표현 파이썬 (0) | 2021.03.15 |
| [프로그래머스] 다음 큰 숫자 (0) | 2021.03.15 |
| [프로그래머스] 가장 큰 정사각형 찾기 파이썬 (DP) (0) | 2021.03.15 |
| [프로그래머스] 쿼드압축 후 개수 세기 파이썬 (0) | 2021.03.15 |
댓글