| Conditions | 7 |
| Paths | 16 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function commonChars(array $arr): array |
||
| 10 | { |
||
| 11 | if (empty($arr)) { |
||
| 12 | return []; |
||
| 13 | } |
||
| 14 | [$start, $cnt, $end] = [97, 26, 122]; |
||
| 15 | [$ans, $map] = [[], array_fill($start, $cnt, PHP_INT_MAX)]; |
||
| 16 | foreach ($arr as $str) { |
||
| 17 | $tmp = array_fill($start, $cnt, 0); |
||
| 18 | for ($i = 0, $n = strlen($str); $i < $n; $i++) { |
||
| 19 | $tmp[ord($str[$i])]++; |
||
| 20 | } |
||
| 21 | for ($i = $start; $i <= $end; $i++) { |
||
| 22 | $map[$i] = min($map[$i], $tmp[$i]); |
||
| 23 | } |
||
| 24 | } |
||
| 25 | for ($i = $start; $i <= $end; $i++) { |
||
| 26 | while ($map[$i]-- > 0) { |
||
| 27 | $ans[] = chr($i); |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | return $ans; |
||
| 32 | } |
||
| 34 |