Problem of the Day
A new programming or logic puzzle every Mon-Fri

Palindrome

Hope everyone is coming back from a great weekend!

We've done some stuff with palindromes before but let's change it up one more time. This time around we're going to create a function that takes in a string and determines if a string is a palindrome or not.

Permalink: http://problemotd.com/problem/palindrome/

Comments:

  • Andreas - 10 years, 3 months ago

    Allowing for whitespaces and punctuation within the string.

    def isPalindrome(str: String) = {
      val cleanedUp = str.replaceAll("[\\s\\p{Punct}]","").toLowerCase
      cleanedUp.equals(cleanedUp.reverse)
    }
    

    scala> isPalindrome("Rise to vote, sir!")

    res1: Boolean = true

    reply permalink

  • Nick Krichevsky - 10 years, 3 months ago

    def palendrome(string):
        if string[::-1]==string:
            return True
        return False
    

    reply permalink

Content curated by @MaxBurstein