-
Notifications
You must be signed in to change notification settings - Fork 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
Laura | Nodes #35
base: master
Are you sure you want to change the base?
Laura | Nodes #35
Conversation
i = 0 | ||
j = my_phrase.length - 1 | ||
while i < my_phrase.length | ||
if my_phrase[i] == " " |
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.
To account for multiple, consecutive white spaces, consider making the conditional statements on line 29 and line 33 into while loops.
|
||
i = 0 | ||
j = my_phrase.length - 1 | ||
while i < my_phrase.length |
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 does not need to go through all indices from 0 through length-1, It's sufficient to reach mid-way through the string to confirm whether the string is a palindrome or not. (Similar to string_reverse).
So, line 28, could simply be i < j
.
@@ -1,5 +1,44 @@ | |||
# A method to check if the input string is a palindrome. | |||
# Return true if the string is a palindrome. Return false otherwise. | |||
# Time: O(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.
With regards to time and space complexities: Always explain what n stands for while explaining your time and space complexity. That along with your explanation for reasoning behind your answer, is the complete answer for the time and space complexity. In this case, n is the number of characters in the input string parameter.
Your algorithm is getting to place where it can work in all scenarios. See some comments added inline on the algorithm and on explaining the time and space complexities. Slack me if you have any questions. |
time and space complexity in comments of my code