mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-31 02:53:42 +00:00
Update 63. 股票的最大利润.md
更新题目链接与方法名称,补充股票多次买卖及包含限制条件等相关拓展题目的指引链接。
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
## 题目链接
|
||||
|
||||
[Leetcode:121. Best Time to Buy and Sell Stock ](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/)
|
||||
[Leetcode](https://leetcode.cn/problems/gu-piao-de-zui-da-li-run-lcof/)
|
||||
|
||||
## 题目描述
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
|
||||
使用贪心策略,假设第 i 轮进行卖出操作,买入操作价格应该在 i 之前并且价格最低。因此在遍历数组时记录当前最低的买入价格,并且尝试将每个位置都作为卖出价格,取收益最大的即可。
|
||||
|
||||
可以多次买卖的版本见[买卖股票的最大收益 II](Leetcode%20题解%20-%20贪心思想.md#6-买卖股票的最大收益-ii),有冷却期、手续费或交易次数限制的版本见[股票交易](Leetcode%20题解%20-%20动态规划.md#股票交易)。
|
||||
|
||||
```java
|
||||
public int maxProfit(int[] prices) {
|
||||
public int bestTiming(int[] prices) {
|
||||
if (prices == null || prices.length == 0)
|
||||
return 0;
|
||||
int soFarMin = prices[0];
|
||||
|
||||
Reference in New Issue
Block a user