-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
50 lines (27 loc) · 909 Bytes
/
index.php
File metadata and controls
50 lines (27 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
* Funcion para retornar cantidad de letras repetidas en continuidad
*/
function repeatedLetters(string $string):array {
$groups = [];
$group = [];
foreach (str_split($string) as $value) {
if (isset($group[$value])) {
$group[$value] += 1;
}else{
if (count($group)>0) {
$groups = addResult($groups, $group);
}
$group = [
$value => 1
];
}
}
$groups = addResult($groups, $group);
return $groups;
}
function addResult(array $groups, array $group): array{
array_push($groups, [array_key_first($group), reset($group)]);
return $groups;
}
echo json_encode(repeatedLetters("aaaabbbbbcca"));