From 2e0e0f39d49296f0ffb99aea533a527174521d61 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 15 Dec 2017 10:14:03 +0800 Subject: 62 --- Computer_Science/leetcode/62-unique_paths.c | 33 ++++++++++++++++++++++++ Computer_Science/leetcode/62-unique_paths.c.out | Bin 0 -> 8480 bytes Computer_Science/leetcode/62-unique_paths.c~ | 10 +++++++ Computer_Science/leetcode/63-unique_paths_II.c | 0 4 files changed, 43 insertions(+) create mode 100644 Computer_Science/leetcode/62-unique_paths.c create mode 100755 Computer_Science/leetcode/62-unique_paths.c.out create mode 100644 Computer_Science/leetcode/62-unique_paths.c~ create mode 100644 Computer_Science/leetcode/63-unique_paths_II.c 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 +#include +#include + +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 Binary files /dev/null and b/Computer_Science/leetcode/62-unique_paths.c.out 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 + +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 -- cgit v1.2.3