Skip to content

Instantly share code, notes, and snippets.

@dustingetz
Last active December 14, 2015 15:49
Show Gist options
  • Select an option

  • Save dustingetz/5110801 to your computer and use it in GitHub Desktop.

Select an option

Save dustingetz/5110801 to your computer and use it in GitHub Desktop.
find longest palindrome in a block of text
def longestPalindrome3(haystack: String): String =
(for {
substrSize <- (haystack.length to 1 by -1).toStream # toStream makes the palindromes seq lazy
substr <- haystack.sliding(substrSize)
if (isPalindrome(substr))
} yield substr).headOption.getOrElse("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment