-
Notifications
You must be signed in to change notification settings - Fork 48
Leaves_Ga-Young #42
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_Ga-Young #42
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, your reverse_sentence has O(n2) time complexity, and this could be revised, but it does work and it's in place!
Take a look at my comments and let me know if you have any questions.
|
|
||
| while char_count < my_sentence.length | ||
| if my_sentence[0] != " " | ||
| my_sentence.insert(position_count - 1, my_sentence[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.
Just a note, that insert is an O(n) operation. Could you do this reverse_sentence in O(n) time complexity?
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n^2) where n is the length of string | ||
| # Space complexity: O(n) where n is the length of 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.
Since you're not making a new array, this is actually O(1).
| # Space complexity: ? | ||
| # Time complexity: O(n^2) where n is the length of array | ||
| # Space complexity: O(n) where n is length of string/array | ||
| 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 bubblesort with accurate complexity
Sorting & Reverse Sentence