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

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

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

22条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 12:30

    I would use memoization. That way you can write the method as a recursive call, and still get most of the benefits of a linear implementation.

提交回复
热议问题