aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Computer_Science/leetcode/62-unique_paths.c33
-rwxr-xr-xComputer_Science/leetcode/62-unique_paths.c.outbin0 -> 8480 bytes
-rw-r--r--Computer_Science/leetcode/62-unique_paths.c~10
-rw-r--r--Computer_Science/leetcode/63-unique_paths_II.c0
4 files changed, 43 insertions, 0 deletions
diff --git a/Computer_Science/leetcode/62-unique_paths.c b/Computer_Science/leetcode/62-unique_paths.c
new file mode 100644
index 0000000..6f613fa
--- /dev/null
+++ b/Computer_Science/leetcode/62-unique_paths.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int uniquePaths(int m, int n)
+{
+ int i, j;
+ int *matrix = malloc(sizeof(int) * m * n);
+
+ if(m <= 1 || n <= 1)
+ return 1;
+
+ for(i = 0; i < m; i++) {
+ for(j = 0; j < n; j++) {
+ *(matrix + i * n + j) = 1;
+ }
+ }
+
+ for(i = 1; i < m; i++) {
+ for(j = 1; j < n; j++) {
+ *(matrix + i * n + j) =
+ *(matrix + i * n + j-1)
+ + *(matrix + (i - 1) * n + j);
+ }
+ }
+
+ return *(matrix + m * n - 1);
+}
+
+int main()
+{
+ printf("%d\n", uniquePaths(3, 7));
+}
diff --git a/Computer_Science/leetcode/62-unique_paths.c.out b/Computer_Science/leetcode/62-unique_paths.c.out
new file mode 100755
index 0000000..11f22aa
--- /dev/null
+++ b/Computer_Science/leetcode/62-unique_paths.c.out
Binary files differ
diff --git a/Computer_Science/leetcode/62-unique_paths.c~ b/Computer_Science/leetcode/62-unique_paths.c~
new file mode 100644
index 0000000..3ba5540
--- /dev/null
+++ b/Computer_Science/leetcode/62-unique_paths.c~
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int uniquePaths(int m, int n)
+{
+}
+
+int main()
+{
+ printf("%d\n", uniquePaths(3, 7));
+}
diff --git a/Computer_Science/leetcode/63-unique_paths_II.c b/Computer_Science/leetcode/63-unique_paths_II.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Computer_Science/leetcode/63-unique_paths_II.c