Skip to content

Commit 09a25b7

Browse files
author
devin
committed
feat: 第 122 题添加新思路
1 parent 60cb477 commit 09a25b7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/Leetcode_Solutions/Python/0122._Best_Time_to_Buy_and_Sell_Stock_II.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ class Solution(object):
5656
return 0
5757
return sum([max(prices[i+1]-prices[i], 0) for i in range(len(prices)-1)])
5858
```
59+
简化思路:因为同一天可以卖买,所以只要第二天价高就卖出,不断积累收益,简单明了
60+
```python
61+
class Solution:
62+
def maxProfit(self, prices: List[int]) -> int:
63+
profit = 0
64+
for i in range(1, len(prices)):
65+
if prices[i] > prices[i-1]:
66+
profit += prices[i] - prices[i-1]
67+
return profit
68+
69+
```

0 commit comments

Comments
 (0)