int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridSize, int* obstacleGridColSize){ double* arr=(double*)calloc(*obstacleGridColSize,sizeof(double)); arr[(*obstacleGridColSize)-1]=1; int i, r=obstacleGridSize; if(obstacleGrid[0][0]==1 || obstacleGrid[r-1][(*obstacleGridColSize)-1]==1) return 0; while(--r>=0){ for(i=(*obstacleGridColSize)-1; i>=0; i--) arr[i]+= (obstacleGrid[r][i])?-arr[i] :(i+1<*obstacleGridColSize)?arr[i+1] :0; } return (int)*arr; }
int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridSize, int* obstacleGridColSize){ double* arr=(double*)calloc(*obstacleGridColSize,sizeof(double)); arr[(*obstacleGridColSize)-1]=1; int i, r=obstacleGridSize; if(obstacleGrid[0][0]==1 || obstacleGrid[r-1][(*obstacleGridColSize)-1]==1) return 0; while(--r>=0){ for(i=(*obstacleGridColSize)-1; i>=0; i--) arr[i]+= (obstacleGrid[r][i])?-arr[i] :(i+1<*obstacleGridColSize)?arr[i+1] :0; } return (int)*arr; }