Skip to content

Instantly share code, notes, and snippets.

@bparanj
Created April 8, 2018 15:59
Show Gist options
  • Save bparanj/b4023ee267dc3966384216a7aa3b7d79 to your computer and use it in GitHub Desktop.
Save bparanj/b4023ee267dc3966384216a7aa3b7d79 to your computer and use it in GitHub Desktop.
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