#
# 
# @param matrix int整型二维数组 the matrix
# @return int整型
#
class Solution:
    def minPathSum(self , matrix ):
        # write code here
        m = len(matrix)
        n = len(matrix[0])
        temp = matrix
        for i in range(0, m):
            for j in range(0, n):
                if(i==0 and j==0):
                    temp[i][j] = temp[i][j]
                elif i==0 and j>0:
                    temp[i][j] += temp[i][j-1]
                elif j==0 and i>0:
                    temp[i][j] += temp[i-1][j]
                else:
                    temp[i][j] += min(temp[i-1][j],temp[i][j-1])
        return temp[m-1][n-1]