-
Notifications
You must be signed in to change notification settings - Fork 48
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
Daniela - Leaves #27
base: master
Are you sure you want to change the base?
Daniela - Leaves #27
Conversation
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.
Overall nice work, take a look at my comments and let me know if you have any questions.
@@ -1,8 +1,20 @@ | |||
# Improved Fibonacci | |||
|
|||
# Time Complexity - ? | |||
# Time Complexity - O(n) | |||
# Space Complexity - ? (should be O(n)) | |||
# Hint, you may want a recursive helper method | |||
def fibonacci(n) |
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.
This works, but you don't need to keep the entire list of fibonacci numbers for the entire length of the recursion. Instead you only need to keep the last two fibonacci numbers.
def super_digit(n) | ||
|
||
|
||
return n if [0,1,2,3,4,5,6,7,8,9].include?(n) == true |
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.
Why not just:
return n if [0,1,2,3,4,5,6,7,8,9].include?(n) == true | |
return n if n < 10 |
# Time Complexity - ? | ||
# Space Complexity - ? | ||
# Time Complexity - O(n), depends on number of digits | ||
# Space Complexity : O(1) as the array of digits will always be same and I will always have same variables (sum, reminder, superdigit) | ||
def refined_super_digit(n, k) |
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.
This works, but you can use the super_digit
method previously to help solve the problem.
No description provided.