Skip to Main Content

Valid Palindrome

Problem URL:Valid Palindrome

My Solution

JavaScript

/**
 * @param {string} s
 * @return {boolean}
 */

const isPalindrome = (s) => {
  let stripped = s.toLowerCase().replace(/[^a-z0-9]/gi, "");

  let reversed = stripped.split("").reverse().join("");

  return stripped === reversed;
};

Python

def isPalindrome(s: str) -> bool:
    my_str = ''.join(c for c in s if c.isalnum()).lower()

    return my_str == my_str[::-1]

Let's Connect

Twitter GitHub LinkedIn