Skip to content

Instantly share code, notes, and snippets.

@janice-wong
Created November 27, 2017 02:46
Show Gist options
  • Select an option

  • Save janice-wong/be4eaf467d821aa6a7ef189279bdaf5f to your computer and use it in GitHub Desktop.

Select an option

Save janice-wong/be4eaf467d821aa6a7ef189279bdaf5f to your computer and use it in GitHub Desktop.
# iterative solution
def palindrome(str)
for i in 0..(str.length/2)
return false if str[i] != str[str.length - 1 - i]
end
return true
end
# recursive solution
def palindrome(str)
return true if str.length <= 1
i = 0
if str[i] == str[str.length - 1 - i]
i = 1
palindrome(str[i..str.length - 1 - i])
else
return false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment