class Solution {
public int maxProfit(int[] prices) {
int profit = 0;
int min = prices[0];
for(int i = 1;i < prices.length;i++){
if(prices[i] > min) profit = Math.max(profit,prices[i] - min);
else min = prices[i];
}
return profit;
}
}
121. 买卖股票的最佳时机
最新推荐文章于 2024-09-01 23:57:01 发布
这是一个关于股票交易的算法实现,通过遍历股票价格数组找到最低价,并计算从最低价到当前位置的最大利润。算法的目标是确定买卖股票的最佳时机以获取最大收益。
3471

被折叠的 条评论
为什么被折叠?



