public class Solution {
public int maxProfit(int[] prices) {
if(prices.length == 0) return 0;
int min = prices[0];
int profit = 0;
for(int i = 1; i < prices.length; ++i) {
if(prices[i] < min)
min = prices[i];
else
if(prices[i] - min > profit)
profit = prices[i] - min;
}
return profit;
}
}
Best Time to Buy and Sell Stock
最新推荐文章于 2022-07-29 20:36:59 发布