| Conditions | 5 |
| Paths | 4 |
| Total Lines | 14 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | public static function distributeCandies(array $candies): int |
||
| 8 | { |
||
| 9 | if (empty($candies)) { |
||
| 10 | return 0; |
||
| 11 | } |
||
| 12 | sort($candies); |
||
| 13 | [$cnt, $len] = [1, count($candies)]; |
||
| 14 | for ($i = 1; $i < $len && $cnt < $len / 2; $i++) { |
||
| 15 | if ($candies[$i] > $candies[$i - 1]) { |
||
| 16 | $cnt++; |
||
| 17 | } |
||
| 18 | } |
||
| 19 | |||
| 20 | return $cnt; |
||
| 21 | } |
||
| 36 |