| Conditions | 3 |
| Paths | 3 |
| Total Lines | 13 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 29 | public static function maxProfit2(array $prices, int $fee): int |
||
| 30 | { |
||
| 31 | $n = count($prices); |
||
| 32 | if ($n <= 0) { |
||
| 33 | return 0; |
||
| 34 | } |
||
| 35 | [$cash, $hold] = [0, -$prices[0] - $fee]; |
||
| 36 | foreach ($prices as $i => $price) { |
||
| 37 | $cash = max($cash, $hold + $price - $fee); |
||
| 38 | $hold = max($hold, $cash - $price); |
||
| 39 | } |
||
| 40 | |||
| 41 | return $cash; |
||
| 42 | } |
||
| 44 |