Palindrome Check
PHP
Easy
5 views
Problem Description
Check if the string is a palindrome ignoring spaces and case.
Input Format
One line string s.
Official Solution
<?php
$inputText=rtrim(stream_get_contents(STDIN));
if($inputText==='') exit;
$inputText=strtolower($inputText);
$t='';
for($i=0,$n=strlen($inputText);$i<$n;$i++) if($inputText[$i]!==' ') $t.=$inputText[$i];
$l=0; $r=strlen($t)-1; $ok=true;
while($l<$r){
if($t[$l]!==$t[$r]){ $ok=false; break; }
$l++; $r--;
}
echo $ok ? 'YES' : 'NO';
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!