-
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
Jackie's Palindrome check #17
base: master
Are you sure you want to change the base?
Conversation
@@ -1,5 +1,26 @@ | |||
# A method to check if the input string is a palindrome. | |||
# Return true if the string is a palindrome. Return false otherwise. | |||
|
|||
#The space complexity is O(1) because no space is alocated to create a new object | |||
#The time complexity is O(n) because the while loop needs to walk through each item in the string n times |
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.
Always explain what n stands for while explaining your time and space complexity. In this case, n is the number of characters in the input string or the length of the input string.
i = 0 | ||
j = my_phrase.length - 1 | ||
while i < j | ||
until 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.
Also continue to check that i is less than j. test case: input string with all white spaces.
until my_phrase[i] != " " | ||
i += 1 | ||
end | ||
until my_phrase[j] != " " |
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.
also continue to check that j is greater than i
Nice work with the algorithm and with explaining the time and space complexity. I added some fit-n-finish comments inline. |
No description provided.