| Conditions | 8 |
| Paths | 12 |
| Total Lines | 33 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | public function solution($A) |
||
| 8 | { |
||
| 9 | $N = count($A); |
||
| 10 | if ($N > 1) { |
||
| 11 | $count = array_count_values($A); |
||
| 12 | arsort($count); |
||
| 13 | $max = 0; |
||
| 14 | $maxValue = 0; |
||
| 15 | foreach ($count as $key => $value) { |
||
| 16 | if ($value > (int) ($N / 2)) { |
||
| 17 | $max = $key; |
||
| 18 | $maxValue = $value; |
||
| 19 | break; |
||
| 20 | } else { |
||
| 21 | return 0; |
||
| 22 | } |
||
| 23 | } |
||
| 24 | $equiCounter = 0; |
||
| 25 | $leftLeader = 0; |
||
| 26 | foreach ($A as $key => $value) { |
||
| 27 | if ($value == $max) { |
||
| 28 | $leftLeader++; |
||
| 29 | } |
||
| 30 | if ($leftLeader > ($key + 1) / 2 && ($maxValue - $leftLeader) > ($N - $key - 1) / 2) { |
||
| 31 | $equiCounter++; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | return $equiCounter; |
||
| 36 | } |
||
| 37 | |||
| 38 | return 0; |
||
| 39 | } |
||
| 40 | } |
||
| 41 |