-
Notifications
You must be signed in to change notification settings - Fork 43
Ports - Ngoc #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Ports - Ngoc #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also briefly explain why here. |
||
| def factorial(number) | ||
| raise NotImplementedError | ||
| if number == nil | ||
| raise ArgumentError | ||
| end | ||
|
|
||
| i = 1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm used to seeing |
||
| while number > 0 | ||
| i = number * i | ||
| number -= 1 | ||
| end | ||
| return i | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you provide time complexity, please explain in a few words what
nmeans. For example, in this case, isnequal to the value ofnumber? Or is it equal to the number of things stored innumber(which would be 1)? Or might it have anything to do with the number of decimal digits needed to representnumber? It's important to definenfor every new problem, since the meaning can change from algorithm to algorithm.