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-07-25 23:22:43 发布