Last active
July 3, 2016 17:05
-
-
Save tirjok/012e56cd36e8e0284e2488b6fb5ac838 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 | |
$_fp = fopen("php://stdin", "r"); | |
$str = trim(fgets($_fp)); | |
$str = str_split($str); | |
function removeAdjacent($s, $len) | |
{ | |
$j = 0; | |
for ($i = 1; $i < $len; $i++) { | |
while (($j >= 0) && $i < $len && $s[$i] == $s[$j]) { | |
$i++; | |
$j--; | |
} | |
if ($i < $len) { | |
$s[++$j] = $s[$i]; | |
} | |
} | |
$uniqChar = []; | |
for ($k = 0; $k <= $j; $k++) { | |
$uniqChar[$k] = $s[$k]; | |
} | |
return $uniqChar; | |
} | |
$str = removeAdjacent($str, count($str)); | |
if (count($str)) { | |
echo implode('', $str); | |
} else { | |
echo 'Empty String'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment