You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #107 on September 15, 2026 11:08.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/minimum-falling-path-sum-ii
Problem Summary
행끼리 인접하지 않은 열의 수를 더해서 최소가 되도록 맨 아래까지 가는 합을 구하는 문제.
Solution
O(n^3) 풀이는 매우 쉬운 DP. O(n^2) 풀이를 생각해보자.
그리디하게 생각해보면 된다.
다음 row로 넘어갈 때 col이 같지만 않으면 된다. 즉, col이 어떤 곳이라도 찍을 수 있다는 것. 이를 잘 이용하면 전체 스캔할 필요 없이 최솟값인 곳과 두번째 최솟값인 곳만을 탐색할 수 있다.
문제의 1번 예시를 보면 두번째 row에서 답이 될 수 있는 첫번째 row의 값은 1과 2밖에 없다. 3을 찍을 경우 1, 2를 찍었을 때보다 전체 합이 커지게 된다.
즉 모든 row를 탐색할 필요 없이 이전 까지의 합의 최솟값과 두번째 최솟값인 값들만 탐색해주면 된다. -> O(n^2)
Source Code
O(n^3)
O(n^2)
All reactions