Last active
February 18, 2021 13:01
-
-
Save ALEXOTANO/26bde7f2ecf4d44e6bf0782a015933f7 to your computer and use it in GitHub Desktop.
Check if a string is a valid palindrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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