PermMissingElem::solution()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.2
cc 4
eloc 11
nc 6
nop 1
1
<?php
2
3
namespace Lesson01;
4
5
class PermMissingElem
6
{
7
    public function solution($A)
8
    {
9
        $missing = 1;
10
        $count = count($A);
11
        sort($A);
12
        for ($i = 0; $i < $count; $i++) {
13
            if ($A[$i] != $i + 1) {
14
                $missing = $i + 1;
15
                break;
16
            }
17
        }
18
        if ($i == $count) {
19
            $missing = $count + 1;
20
        }
21
22
        return $missing;
23
    }
24
}
25