Skip to content

Instantly share code, notes, and snippets.

@corehello
Created January 12, 2021 03:53
Show Gist options
  • Save corehello/e7f97828371b798ed8404210392cb99a to your computer and use it in GitHub Desktop.
Save corehello/e7f97828371b798ed8404210392cb99a to your computer and use it in GitHub Desktop.
yet another solution for https://leetcode.com/problems/climbing-stairs/ without fibonacci
from math import floor
from functools import reduce
from operator import mul
class Solution:
def climbStairs(self, n: int) -> int:
ret_sum = 0
for i in range(0, floor(n/2)+1):
if i == 0:
ret_sum += 1
continue
ret_sum += int(reduce(mul, range(n-i,n-i-i, -1), 1) / reduce(mul, range(1, i+1), 1))
return ret_sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment