-
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
palindrome finished #33
base: master
Are you sure you want to change the base?
Conversation
# puts palindrome_check("han nah ") | ||
|
||
while i < j do | ||
if my_phrase[i] == 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.
I'd recommend taking care of preceding and trailing white spaces before comparing the two characters. That way when you do compare the character at index i with the character at index j, you can be sure that they are not equal.
if my_phrase[i] == my_phrase[j] | ||
i += 1 | ||
|
||
until my_phrase[i] != " " do |
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 < j
before comparing the character at index i with a white space.
|
||
j -= 1 | ||
|
||
until my_phrase[j] != " " do |
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 < j
before comparing the character at index j with a white space.
Your algorithm is getting close to a fully working solution. I added some comments inline. With regards to time and space complexities, I did not see any comments on it. Take some time deduce and explain the time and space complexities for your algorithm. 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. Slack me if you'd like to discuss further. |
No description provided.