Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Jackie's Palindrome check #17

wants to merge 2 commits into from

Conversation

jfahmy
Copy link

@jfahmy jfahmy commented Oct 7, 2018

No description provided.

@@ -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

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] != " "

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] != " "

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

@shrutivanw
Copy link

Nice work with the algorithm and with explaining the time and space complexity.

I added some fit-n-finish comments inline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants