貪心法-Best Time to Buy and Sell Stock
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;
}
相關文章
- 121|Best Time to Buy and Sell Stock
- [leetcode]Best Time to Buy and Sell StockLeetCode
- Best Time to Buy and Sell Stock系列
- 121. Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock系列分析
- [LeetCode] 121. Best Time to Buy and Sell StockLeetCode
- leetcode_best-time-to-buy-and-sell-stock-iiLeetCode
- [LeetCode] 122. Best Time to Buy and Sell Stock IILeetCode
- leetcode best-time-to-buy-and-sell-stock-iii(Java)LeetCodeJava
- 【Lintcode】393. Best Time to Buy and Sell Stock IV
- LeetCode 309. Best Time to Buy and Sell Stock with CooldownLeetCode
- 【leetcode】40-best-time-to-buy-and-sell-stock 力扣 121. 買賣股票的最佳時機LeetCode力扣
- 42-best-time-to-buy-and-sell-stock-iii 力扣 123. 買賣股票的最佳時機 III力扣
- 【LeetCode】309. Best Time to Buy and Sell Stock with Cooldown 最佳買賣股票時機含冷凍期(Medium)(JAVA)LeetCodeJava
- 44-best-time-to-buy-and-sell-stock-with-cooldown 力扣 309. 買賣股票的最佳時機包含冷凍期力扣
- 貪心法
- Time Series Analysis (Best MSE Predictor & Best Linear Predictor)
- [LeetCode] 2073. Time Needed to Buy TicketsLeetCode
- 【貪心】POJ 3617:Best Cow Line
- PAT-B 1020 月餅【貪心法】
- 【貪心法】奇數陣列 思路解析和程式碼陣列
- 【PAT_1062】To Buy or Not to Buy
- G69 字首線性基+貪心法 CF1100F Ivan and Burgers
- G64【模板】線性基 貪心法 P3812 最大異或和
- TTEC遭勒索軟體攻擊後影響客戶業務 包括Verizon、Best Buy、美國銀行等
- SAP Stock Inconsistency
- The best LeetCode NodesLeetCode
- Best Team With No Conflicts
- SELL 指令碼程式設計指令碼程式設計
- Best Wishes「兔」You!
- 魔功心法-列舉篇
- 題解:P10688 Buy Tickets
- 攻防世界-best_rsa
- 25 Best Java Books In 2022Java
- time time_t tm用法
- How to Buy a Fake Cal Poly Pomona Diploma Quickly?UI
- 矩陣樹定理 BEST 定理矩陣
- [ARC060F] Best Representation