Skip to content

Instantly share code, notes, and snippets.

@finagin
Created May 6, 2019 06:45
Show Gist options
  • Save finagin/de038a8479fc812d5cc21cfed751a1f2 to your computer and use it in GitHub Desktop.
Save finagin/de038a8479fc812d5cc21cfed751a1f2 to your computer and use it in GitHub Desktop.
<?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