| Total Complexity | 13 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class BestTimeToBuyAndSellStockII |
||
| 8 | { |
||
| 9 | public static function maxProfit(array $prices): int |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function maxProfit2(array $prices): int |
||
| 41 | } |
||
| 42 | |||
| 43 | public static function maxProfit3(array $prices): int |
||
| 44 | { |
||
| 45 | $n = count($prices); |
||
| 46 | if ($n <= 0) { |
||
| 47 | return 0; |
||
| 48 | } |
||
| 49 | $ans = []; |
||
| 50 | for ($i = $n - 2; $i >= 0; $i--) { |
||
| 51 | $ans[] = max($prices[$i + 1] - $prices[$i], 0); |
||
| 52 | } |
||
| 53 | |||
| 54 | return array_sum($ans); |
||
|
|
|||
| 55 | } |
||
| 56 | |||
| 57 | public static function maxProfit4(array $prices): int |
||
| 69 | } |
||
| 70 | } |
||
| 71 |