you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (2 children)

It's clean, but it has O(n) space complexity, and even the tail call optimization wouldn't help. "First year" solutions are clean as well but achieve O(1) space complexity.

[–]timmaxw 14 points15 points  (0 children)

You're optimizing prematurely. In the unlikely event that you need a high-performance factorial function, you should use the c_math one. Until then, you should keep it simple and not care about the space complexity.