Created
April 8, 2018 15:59
-
-
Save bparanj/b4023ee267dc3966384216a7aa3b7d79 to your computer and use it in GitHub Desktop.
This file contains 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
def find_palindromes_in_sub_string(input, j, k) | |
while (j >= 0 && k < input.length) | |
if (input[j] != input[k]) | |
break | |
end | |
puts (input[j .. k]) | |
j -= 1 | |
k += 1 | |
end | |
end | |
def find_all_palindrome_substrings(input) | |
for i in 0..input.length-1 | |
find_palindromes_in_sub_string(input, i - 1, i + 1) | |
find_palindromes_in_sub_string(input, i, i + 1) | |
end | |
end | |
p find_all_palindrome_substrings('aabbbaacc') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment