ArrayPartitionI::arrayPairSum()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class ArrayPartitionI
8
{
9
    public static function arrayPairSum(array $nums): int
10
    {
11
        $ans = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $ans is dead and can be removed.
Loading history...
12
        if (empty($nums)) {
13
            return 0;
14
        }
15
        sort($nums);
16
        [$ans, $n] = [0, count($nums)];
17
        for ($i = 0; $i < $n; $i += 2) {
18
            $ans += $nums[$i];
19
        }
20
21
        return $ans;
22
    }
23
}
24