Passed
Push — master ( 078dde...fa793b )
by Jinyun
261:12 queued 151:55
created

SumOfDigitsInTheMinimumNumber   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A sumOfDigits() 0 18 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class SumOfDigitsInTheMinimumNumber
8
{
9
    public static function sumOfDigits(array $nums): int
10
    {
11
        if (empty($nums)) {
12
            return 0;
13
        }
14
        $min = PHP_INT_MAX;
15
        foreach ($nums as $num) {
16
            if ($num < $min) {
17
                $min = $num;
18
            }
19
        }
20
        $sum = 0;
21
        while ($min > 0) {
22
            $sum += $min % 10;
23
            $min /= 10;
24
        }
25
26
        return $sum % 2 === 0 ? 1 : 0;
27
    }
28
}
29