Palindrome Check

Palindrome Check

Easy PHP PHP Strings 37 views
Explanation Complexity

Problem Statement

Check if the string is a palindrome ignoring spaces and case.

Input Format

One line string s.

Output Format

YES or NO.

Example

nurses run
YES

Constraints

|s|

Input / Output Format

Input Format
One line string s.
Output Format
YES or NO.
Constraints
|s|

Examples

Input:
nurses run
Output:
YES

Example Solution (Public)

PHP
<?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';
?>

Official Solution Code

<?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';
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.