We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 416c5d9 commit 371fe96Copy full SHA for 371fe96
algorithms/BestTimeToBuyAndSellStockII/README.md
@@ -1,2 +1,32 @@
1
# Best Time To Buy And Sell Stock
2
-This problem is easy to solve
+This problem is easy to solve by Greedy Algorithm, like below:
3
+```python
4
+class Solution(object):
5
+ def maxProfit(self, prices):
6
+ """
7
+ :type prices: List[int]
8
+ :rtype: int
9
10
+ if len(prices) == 0:
11
+ return 0
12
+
13
+ max_profit = 0
14
+ holder = prices[0]
15
+ max_price = prices[0]
16
17
+ for i in xrange(1, len(prices)):
18
+ price = prices[i]
19
20
+ if price > max_price:
21
+ max_price = price
22
+ elif max_price > price:
23
+ if max_price > holder:
24
+ max_profit += max_price - holder
25
+ holder = price
26
27
28
29
30
31
+ return max_profit
32
+```
0 commit comments