aboutsummaryrefslogtreecommitdiff
path: root/Computer_Science/leetcode/63-unique_paths_II.c
diff options
context:
space:
mode:
Diffstat (limited to 'Computer_Science/leetcode/63-unique_paths_II.c')
-rw-r--r--Computer_Science/leetcode/63-unique_paths_II.c38
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;
+}