class Solution(object):
def minPathSum(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
t=[[0]*len(grid[0])]*len(grid)
for i in range(len(grid)):
for j in range(len(grid[0])):
if i==0 and j==0:
t[i][j]=grid[i][j]
elif i==0:
t[i][j]=t[i][j-1]+grid[i][j]
elif j==0:
t[i][j]=t[i-1][j]+grid[i][j]
else:
t[i][j]=grid[i][j]+min(t[i][j-1],t[i-1][j])
def minPathSum(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
t=[[0]*len(grid[0])]*len(grid)
for i in range(len(grid)):
for j in range(len(grid[0])):
if i==0 and j==0:
t[i][j]=grid[i][j]
elif i==0:
t[i][j]=t[i][j-1]+grid[i][j]
elif j==0:
t[i][j]=t[i-1][j]+grid[i][j]
else:
t[i][j]=grid[i][j]+min(t[i][j-1],t[i-1][j])
return t[-1][-1]
https://www.youtube.com/watch?v=lBRtnuxg-gU