Skip to content

Instantly share code, notes, and snippets.

@ALEXOTANO
Last active February 18, 2021 13:01
Show Gist options
  • Save ALEXOTANO/26bde7f2ecf4d44e6bf0782a015933f7 to your computer and use it in GitHub Desktop.
Save ALEXOTANO/26bde7f2ecf4d44e6bf0782a015933f7 to your computer and use it in GitHub Desktop.
Check if a string is a valid palindrome
<?php
class Solution {
/**
* @param String $s
* @return Boolean
*/
function isPalindrome($s) {
if(! isset($s)) return false;
$s = strtolower($s);
$s = preg_replace("/[\W]/","", $s);
return strrev($s) == $s;
}
}
/**
* @param {string} s
* @return {boolean}
*/
var isPalindrome = function(s) {
if(!s) return false;
s = s.toLowerCase().replace(/\W+/g,'')
return s == s.split('').reverse().join('')
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment