Skip to content

Instantly share code, notes, and snippets.

@tom-lpsd
Created July 13, 2011 15:26
Show Gist options
  • Save tom-lpsd/1080518 to your computer and use it in GitHub Desktop.
Save tom-lpsd/1080518 to your computer and use it in GitHub Desktop.
don't use reverse
isPalindrome :: String -> Bool
isPalindrome str = isPalindrome' str [] (len `div` 2)
where
len = length str
isPalindrome' [] _ _ = True
isPalindrome' xs ys 0 = if len `mod` 2 == 0 then xs == ys else (tail xs) == ys
isPalindrome' (x:xs) ys n = isPalindrome' xs (x:ys) (n - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment