-
Notifications
You must be signed in to change notification settings - Fork 48
Leaves - Katie #45
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?
Leaves - Katie #45
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.
Nice work, take a look at my comments regarding time complexity. Also could you reuse 1 method to do the reverse on individual words?
| return string | ||
| end | ||
|
|
||
| def word_reverse(string) |
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.
👍 O(n)
| return my_sentence | ||
| end | ||
|
|
||
| def string_reverse(string) |
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.
👍 O(n)
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # A method to reverse the words in a sentence, in place. | ||
| # Time complexity: O(n^3) |
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 is actually O(n) as a solution.
| while word_start < word_end do | ||
| temp_i = string[word_start] | ||
| temp_j = string[word_end] | ||
| string[word_start] = temp_j | ||
| string[word_end] = temp_i | ||
| word_start+=1 | ||
| word_end-=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.
This does the same logic as reverse_sentence, so why not make the method flexible enough to be used in both places.
Sorting & Reverse Sentence