MaxProfit   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B solution() 0 19 5
1
<?php
2
3
namespace Lesson07;
4
5
class MaxProfit
6
{
7
    public function solution($A)
8
    {
9
        $N = count($A);
10
        $maxProfit = 0;
11
        if ($N) {
12
            $minPrice = $A[0];
13
            for ($i = 1; $i < $N; $i++) {
14
                if ($A[$i] < $minPrice) {
15
                    $minPrice = $A[$i];
16
                }
17
18
                if ($A[$i] - $minPrice > $maxProfit) {
19
                    $maxProfit = $A[$i] - $minPrice;
20
                }
21
            }
22
        }
23
24
        return $maxProfit;
25
    }
26
}
27