aboutsummaryrefslogtreecommitdiff
path: root/Computer_Science
diff options
context:
space:
mode:
authorSteve Lee <me@xiangyangli.com>2017-12-15 10:14:03 +0800
committerSteve Lee <me@xiangyangli.com>2017-12-15 10:14:03 +0800
commit2e0e0f39d49296f0ffb99aea533a527174521d61 (patch)
tree03c45deb8e1ed80807d7f211361d346644e95a78 /Computer_Science
parent25b4f2abd597ffba22cccea8587d00540577197d (diff)
download42-2e0e0f39d49296f0ffb99aea533a527174521d61.tar.xz
42-2e0e0f39d49296f0ffb99aea533a527174521d61.zip
62
Diffstat (limited to 'Computer_Science')
-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