Created
May 6, 2019 06:45
-
-
Save finagin/de038a8479fc812d5cc21cfed751a1f2 to your computer and use it in GitHub Desktop.
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 | |
function isPalindrome($str) | |
{ | |
$A = ord('A'); | |
$Z = ord('Z'); | |
$a = ord('a'); | |
$z = ord('z'); | |
$Aa = $a - $A; | |
$l = 0; | |
$r = 0; | |
$len = strlen($str); | |
do { | |
do { | |
$sl = ord($str[$l++]); | |
if ($sl >= $A && $sl <= $Z) { | |
$sl += $Aa; | |
} | |
} while (($sl < $a || $sl > $z) && $l + $r < $len); | |
do { | |
$sr = ord($str[$len - 1 - $r++]); | |
if ($sr >= $A && $sr <= $Z) { | |
$sr += $Aa; | |
} | |
} while (($sr < $a || $sr > $z) && $l + $r <= $len); | |
if ($sl !== $sr || $sl < $a || $sl > $z || $sr < $a || $sr > $z) { | |
return false; | |
} | |
} while ($l + $r < $len); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment