diff --git a/lib/factorial.rb b/lib/factorial.rb index 6a4a408..355c45a 100644 --- a/lib/factorial.rb +++ b/lib/factorial.rb @@ -1,6 +1,15 @@ # Computes factorial of the input number and returns it -# Time complexity: ? -# Space complexity: ? +# Time complexity: O(n) +# Space complexity: O(1) def factorial(number) - raise NotImplementedError + if number == nil + raise ArgumentError + end + + i = 1 + while number > 0 + i = number * i + number -= 1 + end + return i end