diff options
| author | Mistivia <i@mistivia.com> | 2025-09-06 23:17:22 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-09-06 23:17:41 +0800 |
| commit | ad95cba8220e2a7c86362caeb76e1a4333e9c2b8 (patch) | |
| tree | 30b31d94e2ceb46d4e946bfa1eb88b956508f760 /0070 | |
| parent | 5dd8dcdc2ccfa89d25a3cb342a2f89c644236971 (diff) | |
refactor
Diffstat (limited to '0070')
| -rw-r--r-- | 0070/main.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/0070/main.c b/0070/main.c new file mode 100644 index 0000000..143eeb3 --- /dev/null +++ b/0070/main.c @@ -0,0 +1,15 @@ +#include <stdlib.h> + +int climbStairsImpl(int n, int* cache) { + if (n == 0) return 1; + if (n < 0) return 0; + if (cache[n] > 0) return cache[n]; + int ret = climbStairsImpl(n-1, cache) + climbStairsImpl(n-2, cache); + cache[n] = ret; + return ret; +} + +int climbStairs(int n) { + int *cache = malloc(sizeof(int) * (n+1)); + return climbStairsImpl(n, cache); +} |
