MinimumDepthOfBinaryTree   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 2
b 0
f 0
dl 0
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A minDepth() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
use leetcode\util\TreeNode;
8
9
class MinimumDepthOfBinaryTree
10
{
11
    public static function minDepth(TreeNode $root = null): int
12
    {
13
        if (!$root) {
14
            return 0;
15
        }
16
        $left = self::minDepth($root->left);
17
        $right = self::minDepth($root->right);
18
19
        return ($left === 0 || $right === 0)
20
            ? $left + $right + 1
21
            : min($left, $right) + 1;
22
    }
23
}
24