Dominator::solution()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.2
cc 4
eloc 11
nc 4
nop 1
1
<?php
2
3
namespace Lesson06;
4
5
class Dominator
6
{
7
    public function solution($A)
8
    {
9
        $N = count($A);
10
        if ($N) {
11
            $count = array_count_values($A);
12
            arsort($count);
13
            foreach ($count as $key => $value) {
14
                if ($value <= (int) ($N / 2)) {
15
                    return -1;
16
                } else {
17
                    return array_search($key, $A);
18
                }
19
            }
20
        }
21
22
        return -1;
23
    }
24
}
25