Solved LeetCode program · 64 of 1,000
#0064 · Minimum Path Sum
Original English source
The grid is a list of 1, 3, 1, 1, 5, 1, 4, 2, and 1. The columns is 3. The size is the number of items in grid. The table is a list of size zeros. Set item 0 of table to item 0 of grid.
For every position from 1 to one less than size.
The row is position divided by columns. The column is position modulo columns. If row is 0, set item position of table to item (position minus 1) of table plus item position of grid. If row is more than 0 and column is 0, set item position of table to item (position minus columns) of table plus item position of grid. If row is more than 0 and column is more than 0, The above is item (position minus columns) of table, The previous is item (position minus 1) of table, The best path is the smaller of above and previous, set item position of table to best path plus item position of grid.
The last is one less than size. Display item last of table.
Expected stdout
7