diff --git a/lib/factorial.rb b/lib/factorial.rb index 6a4a408..349b7f3 100644 --- a/lib/factorial.rb +++ b/lib/factorial.rb @@ -1,6 +1,12 @@ # Computes factorial of the input number and returns it -# Time complexity: ? -# Space complexity: ? +# Time complexity: linear O(n) where n is the number of integers in the number +# Space complexity: constant O(1) def factorial(number) - raise NotImplementedError + raise ArgumentError, "number can't be nil" if !number + factorial = number > 1 ? number: 1 + while number >= 2 + factorial *= (number - 1) + number -= 1 + end + return factorial end