Today I thought about my palindrome detection function, and revised it.
func bool IsPalindrome(s)
return true if s.length < 2
return false if s[0] != s[-1]
return IsPalindrome(s.substring(1, s.length - 1))
end
This version separates the "no brainer" conditions from the recursive call. It also uses tail recursion.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment