Created
November 27, 2017 02:46
-
-
Save janice-wong/be4eaf467d821aa6a7ef189279bdaf5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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