Share my cpp solution


  • 0
    M
    class Solution {
    public:
        int minPathSum(vector<vector<int>>& grid) {
            int m = grid.size();
            if (m < 1) return 0;
            int n = grid[0].size();
            if (n < 1) return 0;
            
            unsigned int row[n + 1] = {0};
            memset(row, 0xff, sizeof(row));
            row[1] = 0;
            for (int i = 0; i < m; i++) {
                for (int j = 0, k = 1; j < n; j++, k++) {
                    row[k] = min(row[j], row[k]) + grid[i][j];
                }
            }
            return row[n];
        }
    };

Log in to reply
 

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