My 4ms DP solution using C++


  • 0
    D

    class Solution {
    public:

    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
        int row = obstacleGrid.size(),column = obstacleGrid[0].size();
        vector<int> dp(column,0);
        dp[0] = 1;
        for (int i = 0;i < row;++i)
            for (int j = 0;j < column;++j) {
                dp[j] = obstacleGrid[i][j]==1?0:j==0?dp[j]^obstacleGrid[i][j]:dp[j]+dp[j-1];
            }
        return dp[column-1];
    }
    

    };


Log in to reply
 

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