I've spent half day trying to figure out this and finally I got working solution. However, I feel like this can be done in simpler way. I think this code is not really readable.
Sorun: Bir dizeden olmayan ilk tekrarlayan karakterini bulun.
$ String = "abbcabz"
Bu durumda, fonksiyon çıktı "c" olmalıdır.
The reason I use concatenation instead of $input[index_to_remove] = ''
in order to remove character from a given string
is because if I do that, it actually just leave empty cell so that my
return value $input[0] does not not return the character I want to return.
Örneğin,
$str = "abc";
$str[0] = '';
echo $str;
Bu irade çıktı "bc"
Ama aslında, eğer test
var_dump($str);
bana verecek:
string(3) "bc"
İşte benim niyeti:
Given: input
while first char exists in substring of input {
get index_to_remove
input = chars left of index_to_remove . chars right of index_to_remove
if dupe of first char is not found from substring
remove first char from input
}
return first char of input
Kod:
function find_first_non_repetitive2($input) {
while(strpos(substr($input, 1), $input[0]) !== false) {
$index_to_remove = strpos(substr($input,1), $input[0]) + 1;
$input = substr($input, 0, $index_to_remove) . substr($input, $index_to_remove + 1);
if(strpos(substr($input, 1), $input[0]) == false) {
$input = substr($input, 1);
}
}
return $input[0];
}