DEV Community

loading...

Discussion on: Daily Challenge #259 - Duplicate Encoder

Collapse
jurerotar profile image
Jure Rotar

Fast and simple PHP solution :)

function replace(string $string): string {
    $string = strtolower($string);
    $values = array_count_values(str_split($string));
    foreach($values as $index => &$key) {
        $values[$index] = $key > 1 ? ')' : '(';
    }
    return strtr($string, $values);
}