Intuition
- Try DFS. Maybe have a TLE.
solution
|
|
problem
With no doubt, TLE
modification
Using DP.
- Save a 2d-array to save the min total when reach the current position.
- When reach the last row, compare the min.
|
|
Follow Up
Using only O(n) extra space, where n is the total number of rows in the triangle
- This problem assumes that the triangle is from 1(top) to n(bottom), so the follow up actually means the length of the bottom row rather than the number of rows.
solution
- Can keep a 1d-array which contains current line minimum number as the previous count will never be used again.
|
|