| Total Complexity | 8 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class DistributeCandies |
||
| 6 | { |
||
| 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 | } |
||
| 22 | |||
| 23 | public static function distributeCandies2(array $candies): int |
||
| 34 | } |
||
| 35 | } |
||
| 36 |