Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f7c5630

Browse files
committed
better solution of Best Time To Buy And Sell Stock II
1 parent 371fe96 commit f7c5630

File tree

1 file changed

+18
-0
lines changed
  • algorithms/BestTimeToBuyAndSellStockII

1 file changed

+18
-0
lines changed

‎algorithms/BestTimeToBuyAndSellStockII/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,23 @@ class Solution(object):
2828
if max_price > holder:
2929
max_profit += max_price - holder
3030

31+
return max_profit
32+
```
33+
or like below:
34+
```python
35+
class Solution(object):
36+
def maxProfit(self, prices):
37+
"""
38+
:type prices: List[int]
39+
:rtype: int
40+
"""
41+
if len(prices) == 0:
42+
return 0
43+
44+
max_profit = 0
45+
for i in xrange(1, len(prices)):
46+
if prices[i] > prices[i - 1]:
47+
max_profit += prices[i] - prices[i - 1]
48+
3149
return max_profit
3250
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /