Python solution with factorial, only have iterate up to n/2

  • 0
    from math import factorial
    class Solution(object):
        def climbStairs(self, n):
            def c(n,k):
                return factorial(n) / (factorial(n-k) * factorial(k))
            return 1 + sum(c(n-i,i) for i in xrange(1, n/2+1))

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.