-
Notifications
You must be signed in to change notification settings - Fork 48
Leaves - Dominique #43
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.
Outstanding work! You hit all the learning goals here. Very well done!
Take a look at my comments and let me know if you have questions.
| def word_reverse(my_sentence, word_start, word_end) | ||
| word_length = word_end - word_start + 1 | ||
|
|
||
| counter = 0 | ||
|
|
||
| while counter != word_length/2 | ||
| temp = my_sentence[word_start] | ||
| my_sentence[word_start] = my_sentence[word_end] | ||
| my_sentence[word_end] = temp | ||
|
|
||
| word_start += 1 | ||
| word_end -= 1 | ||
| counter += 1 | ||
| end | ||
| 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.
I love this helper method! 👍
| until i == my_sentence.length/2 | ||
| temp = my_sentence[i] | ||
| my_sentence[i] = my_sentence[my_sentence.length - i - 1] | ||
| my_sentence[my_sentence.length - i - 1] = temp | ||
| i += 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 could also use the word_reverse method again to reverse the whole string.
| # Space complexity: ? | ||
| # Time complexity: O(n^2) because as the algorithm scales, each nested loop will run n number of times according to the input. | ||
| # Space complexity: O(1) because the same amount of memory will be used regardless of the input size. | ||
| def sort_by_length(my_sentence) |
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.
Nice SmartBubble sort!
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n^2) because as the algorithm scales, each nested loop will run n number of times according to the input. | ||
| # Space complexity: O(1) because the same amount of memory will be used regardless of the input size. |
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.
Technically since you are doing .split, you have O(n) space complexity.
Sorting & Reverse Sentence