diff options
| author | Steve Lee <me@xiangyangli.com> | 2017-12-26 01:33:40 +0800 |
|---|---|---|
| committer | Steve Lee <me@xiangyangli.com> | 2017-12-26 01:33:40 +0800 |
| commit | 79a9c52fa923fc78074d88463449a8b7f95ca3ef (patch) | |
| tree | 80c2b596a7c41124845771dca99abd364e89d4c4 /Computer_Science/leetcode/63-unique_paths_II.c | |
| parent | 2e0e0f39d49296f0ffb99aea533a527174521d61 (diff) | |
| download | 42-79a9c52fa923fc78074d88463449a8b7f95ca3ef.tar.xz 42-79a9c52fa923fc78074d88463449a8b7f95ca3ef.zip | |
update leetcode solution
Diffstat (limited to 'Computer_Science/leetcode/63-unique_paths_II.c')
| -rw-r--r-- | Computer_Science/leetcode/63-unique_paths_II.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Computer_Science/leetcode/63-unique_paths_II.c b/Computer_Science/leetcode/63-unique_paths_II.c index e69de29..b736541 100644 --- a/Computer_Science/leetcode/63-unique_paths_II.c +++ b/Computer_Science/leetcode/63-unique_paths_II.c @@ -0,0 +1,38 @@ +#include <stdio.h> + +int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridRowSize, int obstacleGridColSize) { + int i, j; + int matrix[obstacleGridRowSize][obstacleGridColSize]; + + for(i = 0; i < obstacleGridColSize; i++) { + if(obstacleGrid[0][i] == 0) + matrix[0][i] = 1; + else + for(; i < obstacleGridColSize; i++) + matrix[0][i] = 0; + } + + for(i = 0; i < obstacleGridRowSize; i++) { + if(obstacleGrid[i][0] == 0) + matrix[i][0] = 1; + else + for(; i < obstacleGridRowSize; i++) + matrix[i][0] = 0; + } + + for(i = 1; i < obstacleGridRowSize; i++) { + for(j = 1; j < obstacleGridColSize; j++) { + if(obstacleGrid[i][j] == 1) + matrix[i][j] = 0; + else + matrix[i][j] = matrix[i - 1][j] + matrix[i][j - 1]; + } + } + + return matrix[obstacleGridRowSize - 1][obstacleGridColSize - 1]; +} + +int main() +{ + return 0; +} |
