public static int MaxProfit(int[] prices)
{
if (prices.Length < 2) return 0;
int profit = 0;
int cur_min = prices[0];
for(int i = 1; i < prices.Length; i++)
{
profit = Math.Max(profit, prices[i] - cur_min);
cur_min = Math.Min(cur_min, prices[i]);
}
return profit;
}
贪心法-Best Time to Buy and Sell Stock
猜你喜欢
转载自blog.csdn.net/smj20170417/article/details/80623829
今日推荐
周排行