32ms c++


  • 0
    B
    class Solution {
    public:
        int minPathSum(vector< vector<int> >& grid) {
            int row = grid.size(), col = grid[0].size();
            vector< vector<int> > f;
            f.resize(row);
            for(int i=0;i<row;i++)
            {
                for(int j=0;j<col;j++)
                {
                    int up=INT_MAX,left=INT_MAX,tmp;
                    if (i-1>=0) up = f[i-1][j];
                    if (j-1>=0) left = f[i][j-1];
                    if (i==0 && j==0) tmp=0;
                    else tmp =min(up,left);
                    f[i].push_back(tmp+grid[i][j]);
                }
            }
            return f[row-1][col-1];
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.