| Conditions | 6 |
| Paths | 5 |
| Total Lines | 17 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function isMajorityElement(array $nums, int $target): bool |
||
| 10 | { |
||
| 11 | if (empty($nums) || $target <= 0) { |
||
| 12 | return false; |
||
| 13 | } |
||
| 14 | if (($n = count($nums)) === 1) { |
||
| 15 | return $nums[0] === $target; |
||
| 16 | } |
||
| 17 | |||
| 18 | $cnt = 0; |
||
| 19 | foreach ($nums as $num) { |
||
| 20 | if ($num === $target) { |
||
| 21 | $cnt++; |
||
| 22 | } |
||
| 23 | } |
||
| 24 | |||
| 25 | return $cnt * 2 > $n; |
||
| 26 | } |
||
| 28 |