How would you write a non-recursive algorithm to calculate factorials?

后端 未结 22 996
不思量自难忘°
不思量自难忘° 2020-12-10 11:39

How would you write a non-recursive algorithm to compute n!?

22条回答
  •  无人及你
    2020-12-10 12:11

    I love the pythonic solution to this:

    def fact(n): return (reduce(lambda x, y: x * y, xrange(1, n+1)))
    

提交回复
热议问题