-
Notifications
You must be signed in to change notification settings - Fork 47
Leaves - Samantha #33
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?
Conversation
CheezItMan
left a comment
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.
Not bad. You didn't get to the last method and you have one incomplete method as well. Take a look at my comments and let me know if you have questions. We'll go over them in class.
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def factorial(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.
👍
| # Time complexity: O(n^2) | ||
| # Space complexity: O(n^2) |
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.
Correct, can you do better than that?
| # Space complexity: ? | ||
| # Time complexity: O(n^2) | ||
| # Space complexity: O(n^2) | ||
| def reverse(s) |
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.
👍
| raise NotImplementedError, "Method not implemented" | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def reverse_inplace(s, first = 0, last = s.length - 1) |
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.
👍
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def bunny(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.
👍
| raise NotImplementedError, "Method not implemented" | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def nested(s, i = 0) |
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 isn't recursive.
- It won't work in all cases
| end | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def search(array, value, index = 0) |
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.
👍
| # Space complexity: ? | ||
| # Time complexity: O(n^2) | ||
| # Space complexity: O(n^2) | ||
| def is_palindrome(s) |
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.
👍
| def digit_match(n, m) | ||
| raise NotImplementedError, "Method not implemented" | ||
| end | ||
| return 1 if n == 0 && m == 0 | ||
| return 0 if n == 0 || m == 0 | ||
| return 1 if n.to_s[-1] == m.to_s[-1] | ||
| 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.
You're only checking the last digit here.
Maybe use if n % 10 == m % 10 to compare the last digit and then divide by 10 to repeat with the remaining digits.
| def reverse(s) | ||
| raise NotImplementedError, "Method not implemented" | ||
| return s if s.length <= 1 | ||
| rev_s = reverse(s[1..-1]) |
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.
s[1..-1] creates a new array and copies all the individual elements over and so is O(n) by itself.
No description provided.