class Solution {
/**
* @param Integer[] $prices
* @return Integer
*/
function maxProfit($prices) {
$cost = $prices[0];
$maxProfit = 0;
foreach($prices as $price) {
// 最小成本
$cost = min($price, $cost);
// 最大利潤
$maxProfit = max($price - $cost, $maxProfit);
}
return $maxProfit;
}
}