Last active
December 14, 2015 15:49
-
-
Save dustingetz/5110801 to your computer and use it in GitHub Desktop.
find longest palindrome in a block of text
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
| 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