Sharing my C solution


  • 0
    M
    int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridRowSize, int obstacleGridColSize) {
    int rowelement[obstacleGridColSize];
    rowelement[0] = (obstacleGrid[0][0] == 0) ? 1 : 0;
    for (int i=1; i<obstacleGridColSize; i++)
        rowelement[i] = 0;
        
    for (int i=0; i<obstacleGridRowSize; i++) {
        if (obstacleGrid[i][0] == 1)
            rowelement[0] = 0;
        for (int j=1; j<obstacleGridColSize; j++) {
            if (obstacleGrid[i][j] == 1)
                rowelement[j] = 0;
            else
                rowelement[j] += rowelement[j-1];
        }
    }
    return rowelement[obstacleGridColSize-1];
    

    }


Log in to reply
 

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