10 lines js solution


  • 0
    L
    function uniquePathsWithObstacles(obstacleGrid) {
        var arr = Array(cols).fill(0).fill(1, 0, 1);
        
        for (var r = 0; r < obstacleGrid.length; r++) {
            for (var c = 0; c < obstacleGrid[0].length; c++) {
                arr[c] = obstacleGrid[r][c] === 1 ? 0 : (arr[c] + (arr[c - 1] || 0));
            }
        }
        return arr[cols - 1];
    }

Log in to reply
 

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