RemoveElement::removeElement()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 14
rs 10
cc 4
nc 4
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class RemoveElement
8
{
9
    public static function removeElement(array &$nums, int $value): int
10
    {
11
        if (($n = count($nums)) === 0) {
12
            return 0;
13
        }
14
15
        $j = 0;
16
        for ($i = 0; $i < $n; $i++) {
17
            if ($nums[$i] !== $value) {
18
                $nums[$j++] = $nums[$i];
19
            }
20
        }
21
22
        return $j;
23
    }
24
}
25