minCostToMoveChips()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 4
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class MinimumCostToMoveChipsToTheSamePosition
8
{
9
    public static function minCostToMoveChips(array $position): int
10
    {
11
        if (empty($position)) {
12
            return 0;
13
        }
14
        $odd = $even = 0;
15
        foreach ($position as $value) {
16
            $value % 2 === 0 ? $even++ : $odd++;
17
        }
18
19
        return min($odd, $even);
20
    }
21
}
22